package com.jwsoft.manager.core.integration.individuation.helper;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.IdcardUtil;
import cn.hutool.core.util.NumberUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.bifang.assistant.common.vo.SessionInfo;
import com.bifang.engine.assistant.core.enums.AuthStatusEnum;
import com.bifang.engine.assistant.core.enums.BoolEnum;
import com.bifang.engine.assistant.core.exception.AppException;
import com.bifang.engine.assistant.core.utils.SessionUtil;
import com.bifang.engine.cache.redis.RedisHelper;
import com.bifang.module.base.common.vo.common.CommonVO;
import com.bifang.module.base.core.integration.CommonIntegration;
import com.github.pagehelper.PageInfo;
import com.jwsoft.manager.common.constant.EduCache;
import com.jwsoft.manager.common.enums.*;
import com.jwsoft.manager.common.vo.cache.EduOperationCacheDetailVO;
import com.jwsoft.manager.common.vo.cache.EduOperationCacheQueryVO;
import com.jwsoft.manager.common.vo.cache.EduOperationCacheVO;
import com.jwsoft.manager.common.vo.eduCompany.EduCompanyVO;
import com.jwsoft.manager.common.vo.eduEnrollmenBrochure.EduEnrollmenBrochureVO;
import com.jwsoft.manager.common.vo.eduFormEnroll.EduFormEnrollVO;
import com.jwsoft.manager.common.vo.eduFormEnrollParams.EduFormEnrollParamsVO;
import com.jwsoft.manager.common.vo.eduHouse.EduHouseVO;
import com.jwsoft.manager.common.vo.eduHouseDetail.EduHouseDetailVO;
import com.jwsoft.manager.common.vo.eduHousehold.EduHouseholdVO;
import com.jwsoft.manager.common.vo.eduLivePlace.EduLivePlaceVO;
import com.jwsoft.manager.common.vo.eduNetsign.EduNetsignVO;
import com.jwsoft.manager.common.vo.eduSchool.EduSchoolVO;
import com.jwsoft.manager.common.vo.eduSchoolConfig.EduSchoolConfigVO;
import com.jwsoft.manager.common.vo.eduSocialSecurity.EduSocialSecurityVO;
import com.jwsoft.manager.common.vo.eduStudentEnroll.SaveStudentEnrollVO;
import com.jwsoft.manager.common.vo.eduStudentEnrollBefore.EduStudentEnrollBeforeVO;
import com.jwsoft.manager.common.vo.eduStudentEnrollBefore.HouseSchoolVO;
import com.jwsoft.manager.common.vo.eduStudentEnrollBefore.HouseholdSchoolVO;
import com.jwsoft.manager.common.vo.eduStudentEnrollPre.EduStudentEnrollPreKeyVO;
import com.jwsoft.manager.common.vo.eduStudentEnrollPre.EduStudentEnrollPreQueryVO;
import com.jwsoft.manager.common.vo.eduStudentEnrollPre.EduStudentEnrollPreVO;
import com.jwsoft.manager.common.vo.eduStudentEnrollVerification.EduStudentEnrollVerificationVO;
import com.jwsoft.manager.core.dao.model.*;
import com.jwsoft.manager.core.dao.service.*;
import com.jwsoft.manager.core.integration.EduJhjyQuerySyncIntegration;
import com.jwsoft.manager.core.integration.EduStudentEnrollImitateIntegration;
import com.jwsoft.manager.core.integration.EduStudentEnrollJhIntegration;
import com.jwsoft.manager.core.integration.EduSystemConfigIntegration;
import com.jwsoft.manager.core.integration.impl.EduStudentEnrollPreIntegrationImpl;
import com.jwsoft.manager.core.util.EduHelper;
import org.apache.commons.lang3.StringUtils;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.springframework.beans.BeanWrapper;
import org.springframework.beans.BeanWrapperImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

/**
 * 金华模拟报名
 * **/
@Component
public class JhImitateEnrollHelper {
    @Autowired
    private EduStudentEnrollImitateIntegration eduStudentEnrollImitateIntegration;
    @Autowired
    private EduStudentEnrollJhIntegration eduStudentEnrollIntegration;
    @Autowired
    private EduFormSpecialService eduFormSpecialService;
    @Autowired
    private EduZsbAbandonService eduZsbAbandonService;
    @Autowired
    private EduStudentEnrollVerificationService eduStudentEnrollVerificationService;
    @Autowired
    private EduHouseholdService eduHouseholdService;
    @Autowired
    public EduJhjyQuerySyncIntegration eduJhjyQuerySyncIntegration;
    @Autowired
    private EduSchoolService eduSchoolService;

    @Autowired
    private CommonIntegration commonIntegration;
    @Autowired
    public EduStudentEnrollFamilyService eduStudentEnrollFamilyService;
    @Autowired
    private EduSystemConfigIntegration eduSystemConfigIntegration;
    @Autowired
    private EduStudentEnrollImitateService eduStudentEnrollService;
    @Autowired
    private EduFormEnrollService eduFormEnrollService;
    @Autowired
    private EduStudentEnrollPreIntegrationImpl eduStudentEnrollPreIntegration;
    @Autowired
    private RedisHelper redisHelper;
    @Autowired
    RedissonClient redissonClient;
    @Autowired
    EduHelper eduHelper;
    @Autowired
    private EduStudentEnrollBlacklistService eduStudentEnrollBlacklistService;
    @Autowired
    private EduSchoolLrService eduSchoolLrService;
    @Autowired
    private  EduEnrollmenBrochureService eduEnrollmenBrochureService;
    @Autowired
    private EduSchoolConfigService eduSchoolConfigService;
    @Autowired
    private EduStudentStatusService eduStudentStatusService;
    @Autowired
    private EduStudentEnrollWhiteService eduStudentEnrollWhiteService;
    public String save(SaveStudentEnrollVO vo) {
        String bmKey = EduCache.EDU_ENROLL_MN + vo.getIdcard();
        if (redisHelper.hasKey(bmKey)) {
            throw new AppException("报名保存处理中，如遇到问题，请等待10分钟后再试");
        }
        redisHelper.set(bmKey, true, 600);
        try{
            checkSave(vo);
        }catch (AppException e){
            redisHelper.del(bmKey);
            throw e;
        }catch (Exception e){
            redisHelper.del(bmKey);
            throw new AppException("系统异常",e);
        }
        EduStudentEnrollImitate eduStudentEnroll=Convert.convert(EduStudentEnrollImitate.class,vo);
        //判断是否随迁
        if (StringUtils.isBlank(eduStudentEnroll.getFollowingFlag())) {
            QueryWrapper<EduHousehold> queryWrapper = new QueryWrapper<>();
            queryWrapper.lambda().eq(EduHousehold::getYear, eduStudentEnroll.getYear())
                    .eq(EduHousehold::getIdcard, eduStudentEnroll.getIdcard())
                    .eq(EduHousehold::getAuthStatus, AuthStatusEnum.YES.getType())
                    .eq(EduHousehold::getAreaCode, eduStudentEnroll.getAreaCode());
            if (eduHouseholdService.count(queryWrapper) > 0) {
                //有户籍认为非随迁
                eduStudentEnroll.setFollowingFlag(BoolEnum.TRUE.getType());
            } else {
                if (BoolEnum.TRUE.getType().equalsIgnoreCase(eduStudentEnroll.getSpecialFlag())) {
                    //特殊通道认为非随迁
                    eduStudentEnroll.setFollowingFlag(BoolEnum.TRUE.getType());
                } else {
                    if ("A".equalsIgnoreCase(eduStudentEnroll.getConfigName()) || "B".equalsIgnoreCase(eduStudentEnroll.getConfigName())) {
                        //A类B类认为是非随迁
                        eduStudentEnroll.setFollowingFlag(BoolEnum.TRUE.getType());
                    } else {
                        eduStudentEnroll.setFollowingFlag(BoolEnum.FALSE.getType());
                    }
                }
            }
        }
        //设置为待审核状态
        if(vo.getLrFlag()){

            //设置数据
            eduStudentEnroll.setConfigName(vo.getConfigName());
            eduStudentEnroll.setConfigTypeName(vo.getConfigTypeName());
            eduStudentEnroll.setFormId(vo.getFormId());
            eduStudentEnroll.setRemarks(vo.getRemarks());
            eduStudentEnroll.setSource("6");//学校录入
            eduStudentEnroll.setParam20(vo.getParam20());
            eduStudentEnroll.setDeployFlag(BoolEnum.FALSE.getType());
            eduStudentEnroll.setAdmitFlag(BoolEnum.TRUE.getType());
            eduStudentEnroll.setAuthStatus(AuthStatusEnum.YES.getType());
            eduStudentEnroll.setAuthUserId(SessionUtil.getUserId());
            eduStudentEnroll.setAuthTime(new Date());
            eduStudentEnroll.setEnrollStatus(EnrollStatusFormalEnum.lq.getType());
            eduStudentEnroll.setAdmitTime(new Date());
            eduStudentEnroll.setAspirationType("0");
            eduStudentEnroll.setAdmitRemarks("学校直接录入录取");

            //查询所属学校配置表
            QueryWrapper<EduSchoolConfig> configQueryWrapper = new QueryWrapper<>();
            configQueryWrapper.lambda().select(EduSchoolConfig::getEnrolment, EduSchoolConfig::getSerialNumEnd)
                    .eq(EduSchoolConfig::getSchoolId, vo.getSchoolId())
                    .eq(EduSchoolConfig::getAuthStatus, AuthStatusEnum.YES.getType())
                    .eq(EduSchoolConfig::getStatus, BoolEnum.TRUE.getType())
                    .eq(EduSchoolConfig::getYear, vo.getYear());
            if ("1".equals(vo.getSchoolNature()) || "2".equals(vo.getSchoolNature())) {
                configQueryWrapper.lambda().eq(EduSchoolConfig::getConfigTypeName, vo.getConfigTypeName());
            }
            EduSchoolConfig eduSchoolConfig = eduSchoolConfigService.getOne(configQueryWrapper, false);
            if (StringUtils.isBlank(eduStudentEnroll.getApplyId())) {
                //设置applYId
                Integer orderNo = 0;
                if ("0".equals(eduStudentEnroll.getSchoolNature())) {
                    if (StringUtils.isBlank(eduStudentEnroll.getFormId())) {
                        throw new AppException("报名表单id不能为空");
                    }
                    EduFormEnroll eduFormEnroll = eduFormEnrollService.getById(eduStudentEnroll.getFormId());
                    eduStudentEnroll.setSpecialFlag(BoolEnum.FALSE.getType());
                    if (eduFormEnroll == null) {
                        EduFormSpecial eduFormSpecial = eduFormSpecialService.getById(eduStudentEnroll.getFormId());
                        if (eduFormSpecial == null) {
                            throw new AppException("未匹配到学校配置的报名表单，如果疑问，请拨打学校电话了解详细情况");
                        }
                        orderNo = 99;
                        eduStudentEnroll.setConfigTypeName(eduFormSpecial.getBigClassValue());
                        eduStudentEnroll.setSpecialFlag(BoolEnum.TRUE.getType());

                    }else{
                        if (!eduFormEnroll.getValidStatus().equals(BoolEnum.TRUE.getType())) {
                            throw new AppException("学校配置报名表单已无效，如果疑问，请拨打学校电话了解详细情况");
                        }
                        orderNo = eduFormEnroll.getOrderNo();
                        //判断年龄是否符合，不是特殊通道类别，需要判断年龄
                        if (StringUtils.isBlank(vo.getBirthYmd())) {
                            throw new AppException("出生日期不能为空");
                        }
                        String birthday = "";
                        if (vo.getBirthYmd().length() >= 8) {
                            birthday = vo.getBirthYmd().replaceAll("-", "").replaceAll("/", "");
                        } else if (vo.getBirthYmd().length() == 6) {
                            birthday = vo.getBirthYmd() + "01";
                        } else {
                            throw new AppException("出生日期格式不正确");
                        }
                        Integer birthYmd = Integer.parseInt(birthday);
                        if (eduSchoolConfig.getStartAge() != null) {
                            Integer startBirthday =
                                    Integer.parseInt(
                                            DatePattern.PURE_DATE_FORMAT.format(eduSchoolConfig.getStartAge()));
                            if (birthYmd < startBirthday) {
                                boolean throwFlag=true;
                                if (SchoolCategoryEnum.JUNIOR.getType().equalsIgnoreCase(vo.getSchoolCategory())) {
                                    LambdaQueryWrapper<EduStudentStatus> studentStatusLambdaQueryWrapper=new LambdaQueryWrapper<>();
                                    studentStatusLambdaQueryWrapper.eq(EduStudentStatus::getIdcard,vo.getIdcard())
                                            .eq(EduStudentStatus::getYear,vo.getYear());
                                    if(eduStudentStatusService.count(studentStatusLambdaQueryWrapper)>0){
                                        throwFlag=false;
                                    }
                                }
                                if(throwFlag){
                                    LambdaQueryWrapper<EduStudentEnrollWhite> whiteLambdaQueryWrapper=new LambdaQueryWrapper<>();
                                    whiteLambdaQueryWrapper.eq(EduStudentEnrollWhite::getIdcard,vo.getIdcard())
                                            .eq(EduStudentEnrollWhite::getYear,vo.getYear())
                                            .eq(EduStudentEnrollWhite::getAuthStatus,BoolEnum.TRUE.getType())
                                            .eq(EduStudentEnrollWhite::getSchoolId,vo.getSchoolId());
                                    if(eduStudentEnrollWhiteService.count(whiteLambdaQueryWrapper)<=0){
                                        throw new AppException("年龄不符，如有疑问，请拨打学校电话了解详细情况");
                                    }
                                }
                            }
                        }
                        if (eduSchoolConfig.getEndAge() != null) {
                            Integer endBirthday =
                                    Integer.parseInt(
                                            DatePattern.PURE_DATE_FORMAT.format(eduSchoolConfig.getEndAge()));
                            if (birthYmd > endBirthday) {
                                boolean throwFlag=true;
                                if (SchoolCategoryEnum.JUNIOR.getType().equalsIgnoreCase(vo.getSchoolCategory())) {
                                    LambdaQueryWrapper<EduStudentStatus> studentStatusLambdaQueryWrapper=new LambdaQueryWrapper<>();
                                    studentStatusLambdaQueryWrapper.eq(EduStudentStatus::getIdcard,vo.getIdcard())
                                            .eq(EduStudentStatus::getYear,vo.getYear());
                                    if(eduStudentStatusService.count(studentStatusLambdaQueryWrapper)>0){
                                        throwFlag=false;
                                    }
                                }
                                if(throwFlag){
                                    LambdaQueryWrapper<EduStudentEnrollWhite> whiteLambdaQueryWrapper=new LambdaQueryWrapper<>();
                                    whiteLambdaQueryWrapper.eq(EduStudentEnrollWhite::getIdcard,vo.getIdcard())
                                            .eq(EduStudentEnrollWhite::getYear,vo.getYear())
                                            .eq(EduStudentEnrollWhite::getAuthStatus,BoolEnum.TRUE.getType())
                                            .eq(EduStudentEnrollWhite::getSchoolId,vo.getSchoolId());
                                    if(eduStudentEnrollWhiteService.count(whiteLambdaQueryWrapper)<=0){
                                        throw new AppException("年龄不符，如有疑问，请拨打学校电话了解详细情况");
                                    }
                                }
                            }
                        }
                    }
                } else {
                    if (StringUtils.isBlank(eduStudentEnroll.getConfigTypeName())) {
                        throw new AppException(eduStudentEnroll.getSchoolName() + "的报名类别不能为空");
                    }
                    QueryWrapper<EduSchoolConfig> schoolConfigMbQueryWrapper = new QueryWrapper<>();
                    schoolConfigMbQueryWrapper
                            .lambda()
                            .eq(EduSchoolConfig::getSchoolId, eduStudentEnroll.getSchoolId())
                            .eq(EduSchoolConfig::getAuthStatus, AuthStatusEnum.YES.getType())
                            .eq(EduSchoolConfig::getStatus, BoolEnum.TRUE.getType())
                            .eq(EduSchoolConfig::getConfigTypeName, eduStudentEnroll.getConfigTypeName())
                            .eq(EduSchoolConfig::getYear, eduStudentEnroll.getYear());
                    EduSchoolConfig schoolConfigMb = eduSchoolConfigService.getOne(schoolConfigMbQueryWrapper, false);
                    if (schoolConfigMb == null) {
                        throw new AppException(eduStudentEnroll.getYear() + "年度报名学校报名类别不匹配，如有疑问，请拨打学校电话了解详细情况");
                    }
                    if (schoolConfigMb.getOrderNo() == null) {
                        throw new AppException(eduStudentEnroll.getYear() + "年度报名学校招生计划设置有误，如有疑问，请拨打学校电话了解详细情况");
                    }
                    orderNo = schoolConfigMb.getOrderNo();
                }
                vo.setFormOrderNo(orderNo);
                //生成applyId
                eduStudentEnroll.setApplyId(this.getApplyId(vo.getYear(), vo.getSchoolNature(), vo.getSchoolNum(), vo.getFormOrderNo(), vo.getSchoolId(), 1));
            }

            //判断是否有与采集数据，没有则新增,有则判断是否修改
            EduStudentEnrollPreQueryVO queryVO = new EduStudentEnrollPreQueryVO();
            queryVO.setYear(vo.getYear());
            queryVO.setIdcard(vo.getIdcard());
            queryVO.setAuthStatus(AuthStatusEnum.YES.getType());
            PageInfo<EduStudentEnrollPreVO> list = eduStudentEnrollPreIntegration.getList(queryVO);
            List<EduStudentEnrollPreVO> preList = list.getList();

            if (ObjectUtils.isEmpty(preList)) {
                // 需要新增预采集信息
                EduStudentEnrollPreVO eduStudentEnrollPreVO = createNewEnrollPreVO(vo);
                try {
                    eduStudentEnrollPreIntegration.add(eduStudentEnrollPreVO);
                } catch (Exception e) {
                    redisHelper.del(bmKey);
                    throw new RuntimeException(e);
                }
            } else {
                // 修改与采集信息
                EduStudentEnrollPreVO studentEnrollPre = preList.get(0);
                boolean isUpdate = false;
                try {
                    isUpdate = updateEnrollPreVO(studentEnrollPre, vo);
                } catch (Exception e) {
                    redisHelper.del(bmKey);
                    throw new RuntimeException(e);
                }
                if (isUpdate) {
                    try {
                        studentEnrollPre.setEnrollPreType(EnrollPreTypeEnum.xxlr.getType());
                        eduStudentEnrollPreIntegration.edit(studentEnrollPre);
                    } catch (Exception e) {
                        redisHelper.del(bmKey);
                        throw new RuntimeException(e);
                    }
                }
            }
            //判断是否随迁
            if (StringUtils.isBlank(eduStudentEnroll.getFollowingFlag())) {
                QueryWrapper<EduHousehold> queryWrapper = new QueryWrapper<>();
                queryWrapper.lambda().eq(EduHousehold::getYear, eduStudentEnroll.getYear())
                        .eq(EduHousehold::getIdcard, eduStudentEnroll.getIdcard())
                        .eq(EduHousehold::getAuthStatus, AuthStatusEnum.YES.getType())
                        .eq(EduHousehold::getAreaCode, eduStudentEnroll.getAreaCode());
                if (eduHouseholdService.count(queryWrapper) > 0) {
                    //有户籍认为非随迁
                    eduStudentEnroll.setFollowingFlag(BoolEnum.TRUE.getType());
                } else {
                    if (BoolEnum.TRUE.getType().equalsIgnoreCase(eduStudentEnroll.getSpecialFlag())) {
                        //特殊通道认为非随迁
                        eduStudentEnroll.setFollowingFlag(BoolEnum.TRUE.getType());
                    } else {
                        if ("A".equalsIgnoreCase(eduStudentEnroll.getConfigName()) || "B".equalsIgnoreCase(eduStudentEnroll.getConfigName())) {
                            //A类B类认为是非随迁
                            eduStudentEnroll.setFollowingFlag(BoolEnum.TRUE.getType());
                        } else {
                            eduStudentEnroll.setFollowingFlag(BoolEnum.FALSE.getType());
                        }
                    }
                }
            }
            //录入
            try {
                eduStudentEnrollService.saveOrUpdate(eduStudentEnroll);
            } catch (Exception e) {
                throw new AppException("报名编号重复，请重新点击保存");
            }
            return eduStudentEnroll.getApplyId();
        }else{
            eduStudentEnroll.setEnrollStatus(EnrollStatusFormalEnum.dsh.getType());
            eduStudentEnroll.setAuthStatus(AuthStatusEnum.NODO.getType());
            eduStudentEnroll.setStudentEnrollId(IdUtil.simpleUUID());
            bindIdcard(eduStudentEnroll,vo.getBindIdcardList());

            //公办直升班信息设置为空
            if("0".equals(vo.getSchoolNature())){
                eduStudentEnroll.setPrivateAppointFlag(null);
                eduStudentEnroll.setPrivateAppointStudentId(null);
            }
            //获取报名编号
            RLock lock = redissonClient.getLock(EduCache.EDU_YW_ENROLL + vo.getSchoolId());
            boolean res;
            try {
                //等待锁10s,锁租约时间20s
                res = lock.tryLock(3000, 20000, TimeUnit.MILLISECONDS);
            } catch (InterruptedException e) {
                redisHelper.del(bmKey);
                throw new AppException("系统繁忙，请稍后再试", e);
            }
            String applyId =null;
            if (res) {
                try {
                    applyId = this.getApplyId(vo.getYear(), vo.getSchoolNature(), vo.getSchoolNum(), vo.getFormOrderNo(), vo.getSchoolId(), 1);
                    eduStudentEnroll.setApplyId(applyId);
                    eduStudentEnroll.setAspirationType("0");
                    /**返回值为true或false字段长度不够*/
                    if (eduStudentEnroll.getBbFlag().equals(BoolEnum.FALSE)){
                        eduStudentEnroll.setBbFlag(BoolEnum.FALSE.getType());
                    }else{
                        eduStudentEnroll.setBbFlag(BoolEnum.TRUE.getType());
                    }
                    eduStudentEnrollService.save(eduStudentEnroll);
                    vo.setStudentEnrollId(eduStudentEnroll.getStudentEnrollId());
                    vo.setApplyId(eduStudentEnroll.getApplyId());
                    if(!CollectionUtils.isEmpty(vo.getVerificationVOList())){
                        QueryWrapper<EduStudentEnrollVerification> verificationQueryWrapper=new QueryWrapper<>();
                        verificationQueryWrapper.lambda().select(EduStudentEnrollVerification::getVerificationType).eq(EduStudentEnrollVerification::getStudentEnrollPreId,vo.getStudentEnrollPreId())
                                .eq(EduStudentEnrollVerification::getVerificationStatus,BoolEnum.TRUE.getType())
                                .eq(EduStudentEnrollVerification::getSchoolId,eduStudentEnroll.getSchoolId());
                        List<EduStudentEnrollVerification> oldList=eduStudentEnrollVerificationService.list(verificationQueryWrapper);
                        List<String> vList=new ArrayList<>();
                        if(!CollectionUtils.isEmpty(oldList)){
                            //同个报名学校已核验的情况，不需要重新核验
                            vList=oldList.stream().map(EduStudentEnrollVerification::getVerificationType).distinct().collect(Collectors.toList());
                        }
                        List<EduStudentEnrollVerification> verificationList=new ArrayList<>();
                        for(EduStudentEnrollVerificationVO verificationVO:vo.getVerificationVOList()){
                            if (vList.contains(verificationVO.getVerificationType())){
                                if(VerificationTypeEnum.fwqhj.getType().equalsIgnoreCase(verificationVO.getVerificationType())||VerificationTypeEnum.hj.getType().equalsIgnoreCase(verificationVO.getVerificationType())){
                                    if((StringUtils.isNotBlank(vo.getHouseholdId())&&vo.getHouseholdId().equalsIgnoreCase(verificationVO.getVerificationTypeId()))
                                            ||(StringUtils.isNotBlank(vo.getHouseholdAddress())&&vo.getHouseholdAddress().equalsIgnoreCase(verificationVO.getVerificationAddress()))){
                                        //线下核验过的户籍必须是核对过的同个户籍id或者户籍地址才能跳过
                                        continue;
                                    }
                                }else if(VerificationTypeEnum.fwqfc.getType().equalsIgnoreCase(verificationVO.getVerificationType())||VerificationTypeEnum.fc.getType().equalsIgnoreCase(verificationVO.getVerificationType())){
                                    if((StringUtils.isNotBlank(vo.getHouseId())&&vo.getHouseId().equalsIgnoreCase(verificationVO.getVerificationTypeId()))
                                            ||(StringUtils.isNotBlank(vo.getHouseAdreess())&&vo.getHouseAdreess().equalsIgnoreCase(verificationVO.getVerificationAddress()))){
                                        //线下核验过的房产必须通过房产id或者同个房产地址才能跳过
                                        continue;
                                    }
                                }else{
                                    continue;
                                }
                            }
                            EduStudentEnrollVerification verification=new EduStudentEnrollVerification();
                            verification.setStudentEnrollId(eduStudentEnroll.getStudentEnrollId());
                            verification.setStudentEnrollPreId(vo.getStudentEnrollPreId());
                            verification.setSchoolId(eduStudentEnroll.getSchoolId());
                            verification.setAreaCode(eduStudentEnroll.getAreaCode());
                            verification.setVerificationType(verificationVO.getVerificationType());
                            verification.setVerificationStatus("0");
                            verification.setFileUrl(verificationVO.getFileUrl());
                            verification.setVerificationTypeId(verificationVO.getVerificationTypeId());
                            verification.setVerificationAddress(verificationVO.getVerificationAddress());
                            verificationList.add(verification);
                        }
                        if(!CollectionUtils.isEmpty(verificationList)){
                            eduStudentEnrollVerificationService.saveBatch(verificationList);
                            eduStudentEnroll.setEnrollStatus(EnrollStatusFormalEnum.hy.getType());
                            eduStudentEnroll.setIcertificatioFlag("1");
                            eduStudentEnrollService.updateById(eduStudentEnroll);

                        }

                    }
                    redisHelper.set(bmKey, true, 10);

                } catch (Exception e) {
                    if("0".equals(eduStudentEnroll.getSchoolNature())){
                        String redisKey="ywImitateEnroll:gb:"+vo.getSchoolNature()+":"+vo.getFormOrderNo();
                        redisHelper.del(redisKey);
                    }
                    redisHelper.del(bmKey);
                    throw new AppException("系统繁忙，请多点几次提交");
                }finally {
                    lock.unlock();
                }
            }else{
                redisHelper.del(bmKey);
                throw new AppException("当前时间段该学校报名人数过多，系统繁忙，请稍后再试");
            }
            if(StringUtils.isNotBlank(vo.getAbandonZsbFlag())&&BoolEnum.TRUE.getType().equals(vo.getAbandonZsbFlag())){
                //放弃直升班保存
                EduZsbAbandon eduZsbAbandon=new EduZsbAbandon();
                eduZsbAbandon.setAbandonId(IdUtil.simpleUUID());
                eduZsbAbandon.setUserId(SessionUtil.getUserId());
                eduZsbAbandon.setFullName(eduStudentEnroll.getFullName());
                eduZsbAbandon.setIdcard(eduStudentEnroll.getIdcard());
                eduZsbAbandon.setAbandonFullName(SessionUtil.getFullName());
                eduZsbAbandon.setAbandonIdcard(SessionUtil.getSessionInfo()!=null?SessionUtil.getSessionInfo().getIdcard():"");
                eduZsbAbandonService.save(eduZsbAbandon);
            }
            return  applyId;
        }
    }

    private boolean updateEnrollPreVO(EduStudentEnrollPreVO studentEnrollPre, SaveStudentEnrollVO vo) {
        boolean isUpdate = false;
        //需要校验的属性
        String[] propertiesToCheck = {
                "idcard", "cardType", "fullName", "fatherName", "fatherCardType",
                "fatherIdcard", "motherName", "motherCardType", "motherIdcard",
                "fatherCellphone", "motherCellphone"
        };
        for (String property : propertiesToCheck) {
            try {
                //比对是否有修改
                if (areValuesDifferent(studentEnrollPre, vo, property)) {
                    isUpdate = true;
                    setPropertyValue(studentEnrollPre, vo, property);
                }
            } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
                throw new AppException("学校线下录入比对字段有误",e);
            }
        }
        return isUpdate;
    }
    private void setPropertyValue(EduStudentEnrollPreVO obj1, SaveStudentEnrollVO obj2, String property)
            throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
        try {
            // 使用反射获取属性值
            Method getterVO = SaveStudentEnrollVO.class.getMethod("get" + property.substring(0, 1).toUpperCase() + property.substring(1));
            Object value2 = getterVO.invoke(obj2);
            // 使用反射设置属性值
            Method setter = EduStudentEnrollPreVO.class.getMethod("set" + property.substring(0, 1).toUpperCase() + property.substring(1), value2.getClass());
            setter.invoke(obj1, value2);
        } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
            throw new AppException(e); // 处理反射异常
        }
    }
    private boolean areValuesDifferent(EduStudentEnrollPreVO obj1, SaveStudentEnrollVO  obj2, String property)
            throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
        if (obj1 == null && obj2 == null) {
            return false;
        }
        if (obj1 == null || obj2 == null) {
            //有一方为空，不去比对，表示需要修改
            return true;
        }
        try {
            //发射获取EduStudentEnrollPreVO的属性值
            Method getter = EduStudentEnrollPreVO.class.getMethod("get" + property.substring(0, 1).toUpperCase() + property.substring(1));
            Object value1 = getter.invoke(obj1);
            //发射获取SaveStudentEnrollVO的属性值
            Method getterVO = SaveStudentEnrollVO.class.getMethod("get" + property.substring(0, 1).toUpperCase() + property.substring(1));
            Object value2 = getterVO.invoke(obj2);

            return !Objects.equals(value1, value2);
        } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
            return false;
        }
    }

    private EduStudentEnrollPreVO createNewEnrollPreVO(SaveStudentEnrollVO vo) {
        EduStudentEnrollPreVO enrollPreVO = new EduStudentEnrollPreVO();
        enrollPreVO.setManagerFlag(true);
        enrollPreVO.setIdcard(vo.getIdcard());
        enrollPreVO.setCardType(vo.getCardType());
        enrollPreVO.setFullName(vo.getFullName());
        enrollPreVO.setFatherName(vo.getFatherName());
        enrollPreVO.setFatherCardType(vo.getFatherCardType());
        enrollPreVO.setFatherIdcard(vo.getFatherIdcard());
        enrollPreVO.setMotherName(vo.getMotherName());
        enrollPreVO.setMotherCardType(vo.getMotherCardType());
        enrollPreVO.setMotherIdcard(vo.getMotherIdcard());
        enrollPreVO.setSchoolCategory(vo.getSchoolCategory());
        enrollPreVO.setMotherCellphone(vo.getMotherCellphone());
        enrollPreVO.setFatherCellphone(vo.getFatherCellphone());
        enrollPreVO.setYear(vo.getYear());
        //设置管理员录入
        enrollPreVO.setEnrollPreType(EnrollPreTypeEnum.gl.getType());
        return enrollPreVO;
    }

    public  String getApplyId(Integer year,String schoolNature,String schoolNum,Integer orderNo,String shcoolId,Integer count){
        if(count==null){
            count=count+1;
        }
        if(count>10){
            //超过10次未能比对到不重复的数据，返回报错
            throw new AppException("系统繁忙，请重新点提交");
        }
        String y=year % 100+"";
        String num = StringUtils.leftPad(schoolNum, 9, "0");
        String orderNoId = StringUtils.leftPad(orderNo + "", 2, "0");
        String applyId=y+num+orderNoId;
        if("0".equals(schoolNature)){
            String redisKey="ywImitateEnroll:gb:"+shcoolId+":"+orderNo;
            if(redisHelper.hasKey(redisKey)) {
                String redisApplyId= (String) redisHelper.get(redisKey);
                applyId=String.valueOf(Long.parseLong(redisApplyId)+1);
                redisHelper.set(redisKey,applyId,259200);
            }else{
                //公办
                String max=eduStudentEnrollService.queryMaxApplyId(applyId,shcoolId,year);
                if(StringUtils.isBlank(max)){
                    applyId=applyId+StringUtils.leftPad("1", 4, "0");
                }else{
                    applyId=String.valueOf(Long.parseLong(max)+1);
                }
                redisHelper.set(redisKey,applyId,259200);
            }
            return applyId;
        }else{
            //民办或者公参民转公
            String redisKey="ywImitateEnroll:mb:"+shcoolId+":"+orderNo;
            Integer randomId =null;
            if(redisHelper.hasKey(redisKey)) {

                List<Integer> randomList= (List<Integer>) redisHelper.get(redisKey);
                if(CollectionUtils.isEmpty(randomList)){
                    Integer[] randomNums= NumberUtil.generateBySet(1,9999,3000);
                    randomList=Arrays.stream(randomNums).distinct().collect(Collectors.toList());
                    randomId=randomList.get(0);
                    randomList.remove(randomId);
                    redisHelper.set(redisKey,randomList,259200);
                }else{
                    randomId=randomList.get(0);
                    randomList.remove(randomId);
                    redisHelper.set(redisKey,randomList,259200);
                }

            }else{
                Integer[] randomNums=NumberUtil.generateBySet(1,9999,3000);
                List<Integer> randomList=Arrays.stream(randomNums).distinct().collect(Collectors.toList());
                randomId=randomList.get(0);
                randomList.remove(randomId);
                redisHelper.set(redisKey,randomList,259200);
            }

            applyId=applyId+StringUtils.leftPad(randomId + "", 4, "0");

        }
        QueryWrapper<EduStudentEnrollImitate> queryWrapper=new QueryWrapper<>();
        queryWrapper.lambda().select(EduStudentEnrollImitate::getStudentEnrollId).eq(EduStudentEnrollImitate::getSchoolId,shcoolId)
                .eq(EduStudentEnrollImitate::getYear,year)
                .eq(EduStudentEnrollImitate::getApplyId,applyId);
        if(eduStudentEnrollService.count(queryWrapper)>0){
            applyId=this.getApplyId(year,schoolNature,schoolNum,orderNo,shcoolId,count);
        }
        return applyId;

    }
    //处理绑定摇号
    private void bindIdcard(EduStudentEnrollImitate studentEnroll,List<String> bindIdcardList){
        if(!BoolEnum.TRUE.getType().equalsIgnoreCase(studentEnroll.getBindFlag())){
            return;
        }
        if(CollectionUtils.isEmpty(bindIdcardList)){
            throw new AppException("绑定的学生身份证不能为空");
        }
        QueryWrapper<EduStudentEnrollImitate> queryWrapper=new QueryWrapper<>();
        queryWrapper.lambda()
                .in(EduStudentEnrollImitate::getIdcard,bindIdcardList)
                .eq(EduStudentEnrollImitate::getYear,studentEnroll.getYear())
                .eq(EduStudentEnrollImitate::getSchoolId,studentEnroll.getSchoolId())
                .eq(EduStudentEnrollImitate::getEnrollStatus,EnrollStatusFormalEnum.dsh.getType())
                .eq(SchoolNatureEnum.mb.getType().equalsIgnoreCase(studentEnroll.getSchoolNature())||SchoolNatureEnum.mzg.getType().equalsIgnoreCase(studentEnroll.getSchoolNature()),EduStudentEnrollImitate::getConfigTypeName,studentEnroll.getConfigTypeName())
                .orderByAsc(EduStudentEnrollImitate::getCreateTime,EduStudentEnrollImitate::getApplyId);
        List<EduStudentEnrollImitate> eduStudentEnrolls=eduStudentEnrollService.list(queryWrapper);
        if(CollectionUtils.isEmpty(eduStudentEnrolls)){
            throw new AppException("未找到可绑定摇号的已报名学生信息，请退出重新报名");
        }
        int i=1;
        String bindIdcard="";
        for(EduStudentEnrollImitate eduStudentEnroll:eduStudentEnrolls){
            if(i==1){
                bindIdcard=eduStudentEnroll.getIdcard();
                if(!BoolEnum.TRUE.getType().equalsIgnoreCase(eduStudentEnroll.getBindFlag())||!BoolEnum.TRUE.getType().equalsIgnoreCase(eduStudentEnroll.getBindMianFlag())){
                    eduStudentEnroll.setBindFlag(BoolEnum.TRUE.getType());
                    eduStudentEnroll.setBindMianFlag(BoolEnum.TRUE.getType());
                    eduStudentEnroll.setBindIdcard(bindIdcard);
                    eduStudentEnrollService.updateById(eduStudentEnroll);
                }
            }else{
                if(!BoolEnum.TRUE.getType().equalsIgnoreCase(eduStudentEnroll.getBindFlag())||BoolEnum.TRUE.getType().equalsIgnoreCase(eduStudentEnroll.getBindMianFlag())){
                    eduStudentEnroll.setBindFlag(BoolEnum.TRUE.getType());
                    eduStudentEnroll.setBindMianFlag(BoolEnum.FALSE.getType());
                    eduStudentEnroll.setBindIdcard(bindIdcard);
                    eduStudentEnrollService.updateById(eduStudentEnroll);
                }
            }
            i=i+1;
        }
        studentEnroll.setBindIdcard(bindIdcard);
        studentEnroll.setBindMianFlag(BoolEnum.FALSE.getType());
    }
    public void checkSave(SaveStudentEnrollVO vo) {
        if(vo.getLrFlag()==null){
            vo.setLrFlag(false);
        }
        if(vo.getVerificationFlag()==null){
            vo.setVerificationFlag(false);
        }
        if(vo.getAborigineFlag()==null){
            vo.setAborigineFlag(BoolEnum.FALSE.getType());
        }
        if(vo.getServiceFlag()==null){
            vo.setServiceFlag(BoolEnum.FALSE.getType());
        }

        if(!vo.getLrFlag()&&StringUtils.isBlank(vo.getStudentEnrollPreId())){
            throw new AppException("预采集ID不能为空");
        }
        //校验基本信息
        if(StringUtils.isBlank(vo.getAddress())){
            throw new AppException("请填先写现居住地");
        }
        if(StringUtils.isBlank(vo.getHouseholdPlace())){
            throw new AppException("请填先写户籍地");
        }

        if(StringUtils.isBlank(vo.getIdcard())){
            throw new AppException("学生证件号码不能为空");
        }
        if(StringUtils.isBlank(vo.getFullName())){
            throw new AppException("学生姓名不能为空");
        }
        if(StringUtils.isBlank(vo.getAddress())){
            throw new AppException("学生现居住地不能为空");
        }
        if(StringUtils.isBlank(vo.getHouseholdPlace())){
            throw new AppException("学生户籍地不能为空");
        }
        vo.setIdcard(vo.getIdcard().trim().toUpperCase());
        vo.setFullName(vo.getFullName().trim());
        if(StringUtils.isBlank(vo.getCardType())){
            vo.setCardType(CardTypeEnum.idcard.getType());
        }
        if(CardTypeEnum.idcard.getType().equals(vo.getCardType())&&StringUtils.isNotBlank(vo.getIdcard())){
            if(!IdcardUtil.isValidCard(vo.getIdcard())){
                throw new AppException("学生身份证格式有误");
            }else{
                if (StringUtils.isBlank(vo.getBirthYmd())) {
                    vo.setBirthYmd(IdcardUtil.getBirth(vo.getIdcard()));
                }
                if (StringUtils.isBlank(vo.getSex())) {
                    int gender = IdcardUtil.getGenderByIdCard(vo.getIdcard());
                    if (gender == 1) {
                        // 男
                        vo.setSex("1");
                    } else {
                        // 女
                        vo.setSex("2");
                    }
                }
            }
        }
        //如果不是身份证类型，出生日期和性别就必须填写
        if(!CardTypeEnum.idcard.getType().equals(vo.getCardType())){
            if(StringUtils.isBlank(vo.getSex())){
                throw new AppException("学生性别不能为空");
            }
            if(StringUtils.isBlank(vo.getBirthYmd())){
                throw new AppException("学生出生日期不能为空");
            }
        }
        boolean flag=true;
        if(StringUtils.isNotBlank(vo.getFatherIdcard())){
            if(StringUtils.isBlank(vo.getFatherCardType())){
                vo.setFatherCardType(CardTypeEnum.idcard.getType());
            }
            vo.setFatherIdcard(vo.getFatherIdcard().trim().toUpperCase());
            if(CardTypeEnum.idcard.getType().equals(vo.getFatherCardType())&&!IdcardUtil.isValidCard(vo.getFatherIdcard())){
                throw new AppException("父亲（监护人）身份证格式有误");
            }
            if(StringUtils.isBlank(vo.getFatherName())){
                throw new AppException("父亲（监护人）姓名不能为空");
            }
            vo.setFatherName(vo.getFatherName().trim());
            if(StringUtils.isBlank(vo.getFatherCellphone())){
                throw new AppException("父亲（监护人）联系电话不能为空");
            }
            flag=false;
        }
        if(StringUtils.isNotBlank(vo.getMotherIdcard())){
            if(StringUtils.isBlank(vo.getMotherCardType())){
                vo.setMotherCardType(CardTypeEnum.idcard.getType());
            }
            if(CardTypeEnum.idcard.getType().equals(vo.getMotherCardType())&&!IdcardUtil.isValidCard(vo.getMotherIdcard())){
                throw new AppException("母亲身份证格式有误");
            }
            vo.setMotherIdcard(vo.getMotherIdcard().trim().toUpperCase());
            if(StringUtils.isBlank(vo.getMotherName())){
                throw new AppException("母亲姓名不能为空");
            }
            vo.setMotherName(vo.getMotherName().trim());
            if(StringUtils.isBlank(vo.getMotherCellphone())){
                throw new AppException("母亲联系电话不能为空");
            }
            flag=false;
        }
        if (flag){
            throw new AppException("请先填写父亲（监护人）或母亲信息");
        }
        if(StringUtils.isBlank(vo.getSchoolId())){
            throw new AppException("请先选择报名学校");
        }

        Integer year=vo.getYear();
        if (year==null){
            year=eduHelper.thisYear();
            vo.setYear(year);
        }
        //获取学校信息
        EduSchoolVO eduSchool=eduSchoolService.getDetail(vo.getSchoolId());

        if(eduSchool==null){
            throw new AppException("报名的学校不存在或者不招生，如果疑问，请拨打学校电话了解详细情况");
        }
        vo.setAreaCode(eduSchool.getAreaCode());
        vo.setSchoolNum(eduSchool.getSchoolNum());
        vo.setSchoolNature(eduSchool.getSchoolNature());
        vo.setSchoolName(eduSchool.getSchoolName());
        vo.setSchoolCategory(eduSchool.getSchoolCategory());
        vo.setStreet(eduSchool.getStreet());
        List<EduSchoolConfigVO> configList=eduSchool.getConfigList();
        List<EduFormEnrollVO> formEnrollVOList=eduSchool.getFormList();
        //校验学校是否在招生中
        if(!eduSchool.getHasEnrollFlag()){
            if(eduSchool.getSchoolNature().equalsIgnoreCase(SchoolNatureEnum.gb.getType())){
                throw new AppException(year+"年度报名公办学校招生方案不存在，如有疑问，请拨打学校电话了解详细情况");
            }else{
                throw new AppException(year+"年度报名学校招生方案不存在，如有疑问，请拨打学校电话了解详细情况");
            }

        }
        /*** 模拟报名不需要招生计划
         if(CollectionUtils.isEmpty(configList)){
         if(eduSchool.getSchoolNature().equalsIgnoreCase(SchoolNatureEnum.gb.getType())){
         throw new AppException(year + "年度报名公办学校未配置招生计划，如有疑问，请拨打学校电话了解详细情况");
         }else{
         throw new AppException(year + "年度报名学校未配置招生计划，如有疑问，请拨打学校电话了解详细情况");
         }

         }***/
        EduSchoolConfigVO schoolConfig =null;
        if(!CollectionUtils.isEmpty(configList)) {
            for (EduSchoolConfigVO eduSchoolConfigVO : configList) {
                if (!SchoolNatureEnum.gb.getType().equalsIgnoreCase(eduSchool.getSchoolNature())) {
                    if (eduSchoolConfigVO.getConfigTypeName().equalsIgnoreCase(vo.getConfigTypeName())) {
                        schoolConfig = eduSchoolConfigVO;
                        break;
                    }
                } else {
                    schoolConfig = eduSchoolConfigVO;
                }

            }
            if (schoolConfig == null) {
                if (eduSchool.getSchoolNature().equalsIgnoreCase(SchoolNatureEnum.gb.getType())) {
                    throw new AppException(year + "年度报名公办学校未配置招生计划，如有疑问，请拨打学校电话了解详细情况");
                } else {
                    throw new AppException(year + "年度报名学校未配置招生计划，如有疑问，请拨打学校电话了解详细情况");
                }
            }
        }
        //判断是否在年度招生时间中
        EduOperationCacheQueryVO queryVO=new EduOperationCacheQueryVO();
        queryVO.setClassify("2");
        queryVO.setAreaCode(vo.getAreaCode());
        queryVO.setYear(year);
        EduOperationCacheVO eduOperationCacheVO=eduSystemConfigIntegration.getEduOperation(queryVO);
        if(eduOperationCacheVO==null){
            throw new AppException("本年度义务教育阶段招生参数未配置，请联系系统管理员");
        }
        Map<String, EduOperationCacheDetailVO> operation=eduOperationCacheVO.getOperation();
        EduOperationCacheDetailVO bmOperation=operation.get("YW062");//模拟报名时间
        //判断是否模拟报名业务期
        boolean bmFlag = bmOperation==null?false:bmOperation.isFlag();
        EduOperationCacheDetailVO xxOperation=operation.get("YW023");//学校录入时间

        if(vo.getLrFlag()){
            if (StringUtils.isBlank(vo.getRemarks())) {
                throw new AppException("请输入录取依据");
            }
            if (StringUtils.isBlank(vo.getParam20())) {
                throw new AppException("必须传入佐证资材料");
            }
            //判断是否在黑名单
            //检验是否在黑名单中，黑名单中不能线下录入
            QueryWrapper<EduStudentEnrollBlacklist> blacklistQueryWrapper = new QueryWrapper<>();
            blacklistQueryWrapper.lambda().eq(EduStudentEnrollBlacklist::getIdcard, vo.getIdcard())
                    .eq(EduStudentEnrollBlacklist::getYear, vo.getYear())
                    .eq(EduStudentEnrollBlacklist::getStatus, BoolEnum.TRUE.getType())
                    .eq(EduStudentEnrollBlacklist::getAreaCode, eduSchool.getAreaCode());
            if (eduStudentEnrollBlacklistService.count(blacklistQueryWrapper) > 0) {
                throw new AppException("该学生申请过退出金华市区内报名，不能重新录入");
            }
            //学校录入
            vo.setSource("6");
            if(xxOperation==null){
                throw new AppException(year+"年度义务段学校线下报名录入工作尚未开始");
            }
            if(!xxOperation.isFlag()){
                if ("1".equalsIgnoreCase(xxOperation.getType()) || "3".equalsIgnoreCase(xxOperation.getType())) {
                    throw new AppException(year+"年度义务段学校线下报名录入工作尚未开始");
                }else{
                    throw new AppException(year+"年度义务段学校线下报名录入工作已结束");
                }
            }
            vo.setBbFlag(BoolEnum.FALSE.getType());
            vo.setSpareRegisterFlag(BoolEnum.FALSE.getType());
            EduStudentEnrollImitate enroll = null;
            List<String> enrollStatusList=new ArrayList<>();
            enrollStatusList.add(EnrollStatusFormalEnum.hy.getType());
            enrollStatusList.add(EnrollStatusFormalEnum.fs.getType());
            enrollStatusList.add(EnrollStatusFormalEnum.dsh.getType());
            enrollStatusList.add(EnrollStatusFormalEnum.dlq.getType());
            enrollStatusList.add(EnrollStatusFormalEnum.lq.getType());
            QueryWrapper<EduStudentEnrollImitate> otherQueryWrapper = new QueryWrapper<>();
            otherQueryWrapper.lambda().ne(EduStudentEnrollImitate::getSchoolId, vo.getSchoolId())
                    .eq(EduStudentEnrollImitate::getYear, vo.getYear())
                    .in(EduStudentEnrollImitate::getEnrollStatus,enrollStatusList)
                    .eq(EduStudentEnrollImitate::getIdcard, vo.getIdcard());
            if (eduStudentEnrollService.count(otherQueryWrapper) > 0) {
                throw new AppException("该学生已在市内其他学校待审核/待录取/录取，不能直接录入，如有疑问，请联系基教科核对");
            }
            if (StringUtils.isNotBlank(vo.getStudentEnrollId())) {
                enroll = eduStudentEnrollService.getById(vo.getStudentEnrollId());
                if (EnrollStatusFormalEnum.lq.getType().equals(enroll.getEnrollStatus())) {
                    throw new AppException("该学生已是录取状态，请核对");
                }
                if (EnrollStatusFormalEnum.ywblq.getType().equals(enroll.getEnrollStatus())) {
                    throw new AppException("该学生业务操作为不予录取，如需重新录入，请联系基教科处理数据");
                }
                if (SchoolNatureEnum.gb.getType().equals(vo.getSchoolNature())) {
                    if (!enroll.getConfigName().equalsIgnoreCase(vo.getConfigName())) {
                        vo.setApplyId(null);
                    }
                }else{
                    if (!enroll.getConfigTypeName().equalsIgnoreCase(vo.getConfigTypeName())) {
                        vo.setApplyId(null);
                    }
                }
            } else {
                QueryWrapper<EduStudentEnrollImitate> enrollQueryWrapper = new QueryWrapper<>();
                enrollQueryWrapper.lambda().select(EduStudentEnrollImitate::getEnrollStatus).eq(EduStudentEnrollImitate::getSchoolId, vo.getSchoolId())
                        .eq(EduStudentEnrollImitate::getYear, vo.getYear())
                        .eq(EduStudentEnrollImitate::getIdcard, vo.getIdcard());
                List<EduStudentEnrollImitate> eduStudentEnrollList = eduStudentEnrollService.list(enrollQueryWrapper);
                if (!CollectionUtils.isEmpty(eduStudentEnrollList)) {
                    enroll = eduStudentEnrollList.get(0);
                    for(EduStudentEnrollImitate oldEnroll:eduStudentEnrollList){
                        if (EnrollStatusFormalEnum.lq.getType().equals(oldEnroll.getEnrollStatus())) {
                            throw new AppException("该学生已是录取状态，请核对");
                        }
                        if (EnrollStatusFormalEnum.ywblq.getType().equals(oldEnroll.getEnrollStatus())) {
                            throw new AppException("该学生业务操作为不予录取，如需重新录入，请联系基教科处理数据");
                        }
                    }
                    vo.setStudentEnrollId(enroll.getStudentEnrollId());
                    if (SchoolNatureEnum.gb.getType().equals(vo.getSchoolNature())) {
                        if (!enroll.getConfigName().equalsIgnoreCase(vo.getConfigName())) {
                            vo.setApplyId(null);
                        }
                    }else{
                        if (!enroll.getConfigTypeName().equalsIgnoreCase(vo.getConfigTypeName())) {
                            vo.setApplyId(null);
                        }
                    }
                } else {
                    if (SchoolNatureEnum.gb.getType().equals(vo.getSchoolNature())) {
                        if(StringUtils.isBlank(vo.getConfigTypeName())){
                            vo.setConfigTypeName("公办");
                        }
                    }
                    vo.setApplyId(null);
                }
            }
            //线下录入人数判断
            //判断学校录入指标管理是否有配置存在
            QueryWrapper<EduSchoolLr> lrQueryWrapper = new QueryWrapper<>();
            lrQueryWrapper.lambda()
                    .eq(EduSchoolLr::getYear,vo.getYear())
                    .eq(EduSchoolLr::getSchoolId,vo.getSchoolId());
            EduSchoolLr schoolLr = eduSchoolLrService.getOne(lrQueryWrapper, false);
            if (ObjectUtils.isEmpty(schoolLr)){
                throw new AppException("未配置学校线下录入指标，请联系教育局进行配置");
            }
            if (schoolLr.getLrCount() == 0){
                throw new AppException(schoolLr.getSchoolName()+"的可录入人数为0，请联系教育局进行配置！");
            }
            long enrollStudentCount = eduStudentEnrollService.count(Wrappers.<EduStudentEnrollImitate>lambdaQuery()
                    .eq(EduStudentEnrollImitate::getYear, vo.getYear())
                    .eq(EduStudentEnrollImitate::getEnrollStatus, EnrollStatusFormalEnum.lq.getType())
                    .eq(EduStudentEnrollImitate::getSchoolId, vo.getSchoolId())
                    .eq(EduStudentEnrollImitate::getSource, "6"));
            if (enrollStudentCount >= schoolLr.getLrCount()){
                throw new AppException("学校线下录入的人数大于系统配置人数指标，无法进行学生录入，请联系教育局进行配置");
            }
            //查询招生方案
            QueryWrapper<EduEnrollmenBrochure> brochureQueryWrapper = new QueryWrapper<>();
            brochureQueryWrapper.lambda().eq(EduEnrollmenBrochure::getYear, vo.getYear())
                    .eq(EduEnrollmenBrochure::getSchoolId, vo.getSchoolId());
            EduEnrollmenBrochure eduEnrollmenBrochure = eduEnrollmenBrochureService.getOne(brochureQueryWrapper, false);
            if (eduEnrollmenBrochure == null) {
                throw new AppException("未找到招生方案信息");
            }
            //超过计划数不能录取
            //计划人数
            Integer enrolment = schoolConfig!=null&&schoolConfig.getEnrolment() == null ? 0 : schoolConfig.getEnrolment();

            //已录取人数
            QueryWrapper<EduStudentEnrollImitate> lqQuery = new QueryWrapper<>();
            lqQuery.lambda().eq(EduStudentEnrollImitate::getEnrollStatus, EnrollStatusFormalEnum.lq.getType())
                    .eq(EduStudentEnrollImitate::getYear, vo.getYear())
                    .eq(EduStudentEnrollImitate::getAdmitFlag, BoolEnum.TRUE.getType())
                    .eq(EduStudentEnrollImitate::getSchoolId, vo.getSchoolId());
            if ("1".equals(vo.getSchoolNature()) || "2".equals(vo.getSchoolNature())) {
                //民办
                lqQuery.lambda().eq(EduStudentEnrollImitate::getConfigTypeName, vo.getConfigTypeName());
            }
            Long lqCount = eduStudentEnrollService.count(lqQuery);
            if (lqCount >= enrolment) {
                throw new AppException("录取人数已到达计划人数，如还需录取，请联系基教科修改招生计划");
            }

        }else {
            EduStudentEnrollPreKeyVO keyVO=new EduStudentEnrollPreKeyVO();
            keyVO.setStudentEnrollPreId(vo.getStudentEnrollPreId());
            EduStudentEnrollPreVO eduStudentEnrollPre=eduStudentEnrollIntegration.getBeforeByPreId(keyVO);
            if(eduStudentEnrollPre==null){
                throw new AppException("未找到新生登记信息");
            }

            vo.setYear(eduStudentEnrollPre.getYear());
            //判断是否有待审核、待录取以及已录取数据，有的话，不能报名
            Boolean enrollFlag= eduStudentEnrollImitateIntegration.checkEnroll(eduStudentEnrollPre.getIdcard(),eduStudentEnrollPre.getYear());
            if(enrollFlag){
                throw new AppException("已报名，请前往我的报名查看报名记录");
            }
            year=vo.getYear();
            if (bmOperation == null) {
                throw new AppException(year + "年度义务段学校招生报名工作尚未开始");
            }
            if (!bmFlag) {
                if ("1".equalsIgnoreCase(bmOperation.getType()) || "3".equalsIgnoreCase(bmOperation.getType())) {
                    throw new AppException(year + "年度义务段学校招生模拟报名工作尚未开始");
                } else {

                    throw new AppException(year + "年度义务段学校招生模拟报名工作已结束");

                }
            }
            if("0".equals(vo.getSchoolNature())){
                if(StringUtils.isBlank(vo.getConfigName())){
                    throw new AppException("请先选择报名类别");
                }
                if(StringUtils.isBlank(vo.getConfigTypeName())){
                    vo.setConfigTypeName("公办");
                }
                if(StringUtils.isBlank(vo.getFormId())){
                    throw new AppException("报名表单id不能为空");
                }
            }else{
                if(StringUtils.isBlank(vo.getConfigTypeName())){
                    throw new AppException("报名类别不能为空");

                }
                if(StringUtils.isBlank(vo.getFormId())){
                    throw new AppException("请先选择报名条件");
                }
            }




            if(!vo.getSchoolCategory().equals(eduSchool.getSchoolCategory())){
                throw new AppException("报名的学段和学校的类型不一致");
            }
            vo.setSchoolNature(eduSchool.getSchoolNature());
            vo.setSchoolNum(eduSchool.getSchoolNum());
            vo.setSchoolName(eduSchool.getSchoolName());
            vo.setStreet(eduSchool.getStreet());


            if ("0".equals(eduSchool.getSchoolNature())) {
                //公办学校
                if (CollectionUtils.isEmpty(formEnrollVOList)) {
                    throw new AppException("未匹配到学校配置的报名表单，如果疑问，请拨打学校电话了解详细情况");
                }
                EduFormEnrollVO eduForm = null;
                for (EduFormEnrollVO eduFormEnrollVO : formEnrollVOList) {
                    if (eduFormEnrollVO.getFormId().equalsIgnoreCase(vo.getFormId())) {
                        eduForm = eduFormEnrollVO;
                        break;
                    }
                }
                if (eduForm == null) {
                    throw new AppException("未匹配到学校配置的报名表单，如果疑问，请拨打学校电话了解详细情况");
                }
                if (BoolEnum.FALSE.getType().equalsIgnoreCase(eduForm.getValidStatus())) {
                    throw new AppException("学校配置报名表单已无效，如果疑问，请拨打学校电话了解详细情况");
                }
                if (eduForm.getOrderNo() == null) {
                    throw new AppException("学校配置报名类别排序号为空，如果疑问，请拨打学校电话了解详细情况");
                }
                vo.setFormOrderNo(eduForm.getOrderNo());
            } else {
                //民办或民转公
                if (StringUtils.isBlank(vo.getConfigTypeName())) {
                    throw new AppException(eduSchool.getSchoolName() + "的报名类别不能为空");
                }

                vo.setFormOrderNo(1);
                if (!CollectionUtils.isEmpty(formEnrollVOList)) {
                    EduFormEnrollVO eduForm = null;
                    for (EduFormEnrollVO eduFormEnrollVO : formEnrollVOList) {
                        if (eduFormEnrollVO.getFormId().equalsIgnoreCase(vo.getFormId())) {
                            eduForm = eduFormEnrollVO;
                            break;
                        }
                    }
                    if (eduForm == null) {
                        throw new AppException("未匹配到学校配置的报名表单，如果疑问，请拨打学校电话了解详细情况");
                    }
                    if (BoolEnum.FALSE.getType().equalsIgnoreCase(eduForm.getValidStatus())) {
                        throw new AppException("学校配置报名表单已无效，如果疑问，请拨打学校电话了解详细情况");
                    }
                    if (eduForm.getOrderNo() == null) {
                        throw new AppException("学校配置报名类别排序号为空，如果疑问，请拨打学校电话了解详细情况");
                    }
                    vo.setFormOrderNo(eduForm.getOrderNo());
                }
            }

            //判断年龄是否符合，特殊标识人员不处理
            if(!BoolEnum.TRUE.getType().equals(vo.getSpecialFlag())) {
                if(StringUtils.isBlank(vo.getSource())){
                    vo.setSource("1");
                }

                if (StringUtils.isBlank(vo.getBirthYmd())) {
                    throw new AppException("出生日期不能为空");
                }
                String birthday = "";
                if (vo.getBirthYmd().length() >= 8) {
                    birthday = vo.getBirthYmd().replaceAll("-", "").replaceAll("/", "");
                } else if (vo.getBirthYmd().length() == 6) {
                    birthday = vo.getBirthYmd() + "01";
                }else{
                    throw new AppException("出生日期格式不正确");
                }
                Integer birthYmd= Integer.parseInt(birthday);
                if (schoolConfig!=null&&schoolConfig.getStartAge() != null) {

                    Integer startBirthday =
                            Integer.parseInt(
                                    DatePattern.PURE_DATE_FORMAT.format(schoolConfig.getStartAge()));
                    if(birthYmd<startBirthday){
                        //初中判断是否学籍，有学籍则不校验年龄
                        boolean throwFlag=true;
                        if (SchoolCategoryEnum.JUNIOR.getType().equalsIgnoreCase(eduSchool.getSchoolCategory())) {
                            LambdaQueryWrapper<EduStudentStatus> studentStatusLambdaQueryWrapper=new LambdaQueryWrapper<>();
                            studentStatusLambdaQueryWrapper.eq(EduStudentStatus::getIdcard,vo.getIdcard())
                                    .eq(EduStudentStatus::getYear,year);
                            if(eduStudentStatusService.count(studentStatusLambdaQueryWrapper)>0){
                                throwFlag=false;
                            }
                        }
                        if(throwFlag){
                            LambdaQueryWrapper<EduStudentEnrollWhite> whiteLambdaQueryWrapper=new LambdaQueryWrapper<>();
                            whiteLambdaQueryWrapper.eq(EduStudentEnrollWhite::getIdcard,vo.getIdcard())
                                    .eq(EduStudentEnrollWhite::getYear,vo.getYear())
                                    .eq(EduStudentEnrollWhite::getSchoolId,vo.getSchoolId());
                            if(eduStudentEnrollWhiteService.count(whiteLambdaQueryWrapper)<=0){
                                throw new AppException("年龄不符，如有疑问，请拨打学校电话了解详细情况");
                            }
                        }

                    }
                }else{
                    if (SchoolCategoryEnum.PRIMARY.getType().equalsIgnoreCase(eduSchool.getSchoolCategory())) {
                        //小学
                        if (eduOperationCacheVO.getOperation().get("YW005") == null) {
                            throw new AppException("招生计划参数，小学允许就读出生日期未配置");
                        }

                        if (ObjectUtils.isEmpty(eduOperationCacheVO.getOperation().get("YW005").getBegTime()) || ObjectUtils.isEmpty(eduOperationCacheVO.getOperation().get("YW005").getEndTime())){
                            throw new AppException("招生计划参数“YW005” 未配置，联系管理员设置小学允许就读出生日期");
                        }
                        Integer startBirthday =
                                Integer.parseInt(
                                        DatePattern.PURE_DATE_FORMAT.format(eduOperationCacheVO.getOperation().get("YW005").getBegTime()));
                        if(birthYmd<startBirthday){
                            boolean throwFlag=true;
                            if (SchoolCategoryEnum.JUNIOR.getType().equalsIgnoreCase(eduSchool.getSchoolCategory())) {
                                LambdaQueryWrapper<EduStudentStatus> studentStatusLambdaQueryWrapper=new LambdaQueryWrapper<>();
                                studentStatusLambdaQueryWrapper.eq(EduStudentStatus::getIdcard,vo.getIdcard())
                                        .eq(EduStudentStatus::getYear,year);
                                if(eduStudentStatusService.count(studentStatusLambdaQueryWrapper)>0){
                                    throwFlag=false;
                                }
                            }
                            if(throwFlag){
                                LambdaQueryWrapper<EduStudentEnrollWhite> whiteLambdaQueryWrapper=new LambdaQueryWrapper<>();
                                whiteLambdaQueryWrapper.eq(EduStudentEnrollWhite::getIdcard,vo.getIdcard())
                                        .eq(EduStudentEnrollWhite::getYear,vo.getYear())
                                        .eq(EduStudentEnrollWhite::getAuthStatus,BoolEnum.TRUE.getType())
                                        .eq(EduStudentEnrollWhite::getSchoolId,vo.getSchoolId());
                                if(eduStudentEnrollWhiteService.count(whiteLambdaQueryWrapper)<=0){
                                    throw new AppException("年龄不符，如有疑问，请拨打学校电话了解详细情况");
                                }
                            }
                        }

                    } else if (SchoolCategoryEnum.JUNIOR.getType().equalsIgnoreCase(eduSchool.getSchoolCategory())) {
                        if (eduOperationCacheVO.getOperation().get("YW006") == null) {
                            throw new AppException("招生计划参数，初中允许就读出生日期未配置");
                        }
                        if (ObjectUtils.isEmpty(eduOperationCacheVO.getOperation().get("YW006").getBegTime()) || ObjectUtils.isEmpty(eduOperationCacheVO.getOperation().get("YW006").getEndTime())){
                            throw new AppException("招生计划参数“YW006” 未配置，请联系管理员设置初中允许就读出生日期");
                        }
                        Integer startBirthday =
                                Integer.parseInt(
                                        DatePattern.PURE_DATE_FORMAT.format(eduOperationCacheVO.getOperation().get("YW006").getBegTime()));
                        if(birthYmd<startBirthday){
                            boolean throwFlag=true;
                            if (SchoolCategoryEnum.JUNIOR.getType().equalsIgnoreCase(eduSchool.getSchoolCategory())) {
                                LambdaQueryWrapper<EduStudentStatus> studentStatusLambdaQueryWrapper=new LambdaQueryWrapper<>();
                                studentStatusLambdaQueryWrapper.eq(EduStudentStatus::getIdcard,vo.getIdcard())
                                        .eq(EduStudentStatus::getYear,year);
                                if(eduStudentStatusService.count(studentStatusLambdaQueryWrapper)>0){
                                    throwFlag=false;
                                }
                            }
                            if(throwFlag){
                                throw new AppException("年龄不符，如有疑问，请拨打学校电话了解详细情况");
                            }
                        }
                    }
                }
                if (schoolConfig!=null&&schoolConfig.getEndAge() != null) {
                    Integer endBirthday =
                            Integer.parseInt(
                                    DatePattern.PURE_DATE_FORMAT.format(schoolConfig.getEndAge()));
                    if(birthYmd>endBirthday){
                        boolean throwFlag=true;
                        if (SchoolCategoryEnum.JUNIOR.getType().equalsIgnoreCase(eduSchool.getSchoolCategory())) {
                            LambdaQueryWrapper<EduStudentStatus> studentStatusLambdaQueryWrapper=new LambdaQueryWrapper<>();
                            studentStatusLambdaQueryWrapper.eq(EduStudentStatus::getIdcard,vo.getIdcard())
                                    .eq(EduStudentStatus::getYear,year);
                            if(eduStudentStatusService.count(studentStatusLambdaQueryWrapper)>0){
                                throwFlag=false;
                            }
                        }
                        if(throwFlag){
                            LambdaQueryWrapper<EduStudentEnrollWhite> whiteLambdaQueryWrapper=new LambdaQueryWrapper<>();
                            whiteLambdaQueryWrapper.eq(EduStudentEnrollWhite::getIdcard,vo.getIdcard())
                                    .eq(EduStudentEnrollWhite::getYear,vo.getYear())
                                    .eq(EduStudentEnrollWhite::getAuthStatus,BoolEnum.TRUE.getType())
                                    .eq(EduStudentEnrollWhite::getSchoolId,vo.getSchoolId());
                            if(eduStudentEnrollWhiteService.count(whiteLambdaQueryWrapper)<=0){
                                throw new AppException("年龄不符，如有疑问，请拨打学校电话了解详细情况");
                            }
                        }
                    }
                }else{
                    if (SchoolCategoryEnum.PRIMARY.getType().equalsIgnoreCase(eduSchool.getSchoolCategory())) {
                        //小学
                        if (eduOperationCacheVO.getOperation().get("YW005") == null) {
                            throw new AppException("招生计划参数，小学允许就读出生日期未配置");
                        }

                        if (ObjectUtils.isEmpty(eduOperationCacheVO.getOperation().get("YW005").getBegTime()) || ObjectUtils.isEmpty(eduOperationCacheVO.getOperation().get("YW005").getEndTime())){
                            throw new AppException("招生计划参数“YW005” 未配置，联系管理员设置小学允许就读出生日期");
                        }
                        Integer endBirthday =
                                Integer.parseInt(
                                        DatePattern.PURE_DATE_FORMAT.format(eduOperationCacheVO.getOperation().get("YW005").getEndTime()));
                        if(birthYmd>endBirthday){
                            boolean throwFlag=true;
                            if (SchoolCategoryEnum.JUNIOR.getType().equalsIgnoreCase(eduSchool.getSchoolCategory())) {
                                LambdaQueryWrapper<EduStudentStatus> studentStatusLambdaQueryWrapper=new LambdaQueryWrapper<>();
                                studentStatusLambdaQueryWrapper.eq(EduStudentStatus::getIdcard,vo.getIdcard())
                                        .eq(EduStudentStatus::getYear,year);
                                if(eduStudentStatusService.count(studentStatusLambdaQueryWrapper)>0){
                                    throwFlag=false;
                                }
                            }
                            if(throwFlag){
                                LambdaQueryWrapper<EduStudentEnrollWhite> whiteLambdaQueryWrapper=new LambdaQueryWrapper<>();
                                whiteLambdaQueryWrapper.eq(EduStudentEnrollWhite::getIdcard,vo.getIdcard())
                                        .eq(EduStudentEnrollWhite::getYear,vo.getYear())
                                        .eq(EduStudentEnrollWhite::getAuthStatus,BoolEnum.TRUE.getType())
                                        .eq(EduStudentEnrollWhite::getSchoolId,vo.getSchoolId());
                                if(eduStudentEnrollWhiteService.count(whiteLambdaQueryWrapper)<=0){
                                    throw new AppException("年龄不符，如有疑问，请拨打学校电话了解详细情况");
                                }
                            }
                        }

                    } else if (SchoolCategoryEnum.JUNIOR.getType().equalsIgnoreCase(eduSchool.getSchoolCategory())) {
                        if (eduOperationCacheVO.getOperation().get("YW006") == null) {
                            throw new AppException("招生计划参数，初中允许就读出生日期未配置");
                        }
                        if (ObjectUtils.isEmpty(eduOperationCacheVO.getOperation().get("YW006").getBegTime()) || ObjectUtils.isEmpty(eduOperationCacheVO.getOperation().get("YW006").getEndTime())){
                            throw new AppException("招生计划参数“YW006” 未配置，请联系管理员设置初中允许就读出生日期");
                        }
                        Integer endBirthday =
                                Integer.parseInt(
                                        DatePattern.PURE_DATE_FORMAT.format(eduOperationCacheVO.getOperation().get("YW006").getEndTime()));
                        if(birthYmd>endBirthday){
                            boolean throwFlag=true;
                            if (SchoolCategoryEnum.JUNIOR.getType().equalsIgnoreCase(eduSchool.getSchoolCategory())) {
                                LambdaQueryWrapper<EduStudentStatus> studentStatusLambdaQueryWrapper=new LambdaQueryWrapper<>();
                                studentStatusLambdaQueryWrapper.eq(EduStudentStatus::getIdcard,vo.getIdcard())
                                        .eq(EduStudentStatus::getYear,year);
                                if(eduStudentStatusService.count(studentStatusLambdaQueryWrapper)>0){
                                    throwFlag=false;
                                }
                            }
                            if(throwFlag){
                                LambdaQueryWrapper<EduStudentEnrollWhite> whiteLambdaQueryWrapper=new LambdaQueryWrapper<>();
                                whiteLambdaQueryWrapper.eq(EduStudentEnrollWhite::getIdcard,vo.getIdcard())
                                        .eq(EduStudentEnrollWhite::getYear,vo.getYear())
                                        .eq(EduStudentEnrollWhite::getAuthStatus,BoolEnum.TRUE.getType())
                                        .eq(EduStudentEnrollWhite::getSchoolId,vo.getSchoolId());
                                if(eduStudentEnrollWhiteService.count(whiteLambdaQueryWrapper)<=0){
                                    throw new AppException("年龄不符，如有疑问，请拨打学校电话了解详细情况");
                                }
                            }
                        }
                    }
                }

            }else{
                if(StringUtils.isBlank(vo.getSource())){
                    vo.setSource("5");
                }
                //判断是否学校特殊人员
                List<EduStudentEnrollBeforeVO> beforeList=eduStudentEnrollPre.getEnrollBeforeList();
                if(CollectionUtils.isEmpty(beforeList)){
                    throw new AppException("不能报该学校政策性安排，如有疑问，请拨打学校电话了解详细情况");
                }else{
                    for(EduStudentEnrollBeforeVO beforeVO:beforeList){
                        if( beforeVO.getSchoolId().equalsIgnoreCase(vo.getSchoolId())){
                            if(BoolEnum.TRUE.getType().equalsIgnoreCase(beforeVO.getSpecialFlag())) {
                                if (beforeVO.getConfigName().equals(vo.getConfigName()) && beforeVO.getConfigTypeName().equals(vo.getConfigTypeName())) {
                                    vo.setConfigTypeName(beforeVO.getConfigTypeName());
                                    vo.setConfigName(beforeVO.getConfigName());
                                    vo.setHouseId(beforeVO.getHouseId());
                                    vo.setHouseholdId(beforeVO.getHouseholdId());
                                    break;

                                } else {
                                    throw new AppException("报名的政策性安排类别与学校录入的不一致，请退出系统重新进入试试，如有疑问，请拨打学校电话了解详细情况");
                                }
                            }
                        }

                    }

                }

            }
            //是否调配
            vo.setDeployFlag(BoolEnum.FALSE.getType());
            //现场核验
            vo.setIcertificatioFlag(BoolEnum.FALSE.getType());
            //线下核验判断
            List<EduStudentEnrollVerificationVO> verificationVOList=new ArrayList<>();
            if(!CollectionUtils.isEmpty(vo.getVerificationVOList())){
                verificationVOList.addAll(vo.getVerificationVOList());
            }
            boolean checkHouse=false;
            boolean checkHousehold=false;
            boolean abcFlag=false;
            EduEnrollmenBrochureVO eduEnrollmenBrochureVO=eduSchool.getEduEnrollmenBrochureVO();
            if("0".equals(vo.getSchoolNature())) {
                //判断是否突破学区
                List<String> schoolIdList = eduSchool.getBreakSchoolList();

                if ("A".equals(vo.getConfigName())) {

                    checkHouse = true;
                    checkHousehold = true;
                    abcFlag = true;
                    if(BoolEnum.TRUE.getType().equalsIgnoreCase(vo.getAborigineFlag())){
                        checkHouse=false;
                    }
                }
                if ("B".equals(vo.getConfigName())) {
                    checkHousehold = true;
                    abcFlag = true;
                }
                if ("C".equals(vo.getConfigName())) {

                    checkHouse = true;
                    abcFlag = true;
                }
                if ("特殊户口".equals(vo.getConfigName())) {

                    checkHousehold = true;
                    abcFlag = true;
                }
                if(BoolEnum.TRUE.getType().equalsIgnoreCase(vo.getServiceFlag())&&!BoolEnum.TRUE.getType().equalsIgnoreCase(eduEnrollmenBrochureVO.getServiceFlag())){
                    throw new AppException("学校未开通服务区报名，不能报服务区的相关类别");
                }
                if (checkHouse) {
                    //校验房产是否存在
                    if(StringUtils.isBlank(vo.getHouseId())&&StringUtils.isBlank(vo.getParam16())){
                        throw new AppException("请传入选择报名使用的房产或上传房产佐证材料");
                    }
                    if(StringUtils.isNotBlank(vo.getHouseId())) {
                        List<EduHouseVO> houseVOList = eduStudentEnrollPre.getHouseList();
                        if (CollectionUtils.isEmpty(houseVOList)) {
                            throw new AppException("未匹配到您名下的房产信息，请使用房产所有者的浙里办账号登录报名。如果匹配信息有误，请联系学校");
                        }
                        EduHouseVO eduHouse = null;
                        for (EduHouseVO eduHouseVO : houseVOList) {
                            if (eduHouseVO.getHouseId().equalsIgnoreCase(vo.getHouseId())) {
                                eduHouse = eduHouseVO;
                                break;
                            }else{
                                if(!CollectionUtils.isEmpty(eduHouseVO.getGyHouseIdList())){
                                    if(eduHouseVO.getGyHouseIdList().contains(vo.getHouseId())){
                                        eduHouse=eduHouseVO;
                                        break;
                                    }
                                }
                            }
                        }
                        if (eduHouse == null || !BoolEnum.TRUE.getType().equals(eduHouse.getStatus())) {
                            throw new AppException("不是有效的房产");
                        }
                        if (BoolEnum.TRUE.getType().equals(eduHouse.getUseFlag())) {
                            throw new AppException("该房产3年内已使用，如有疑问，请致电联系");
                        }
                        if(!CollectionUtils.isEmpty(eduHouse.getAreaCodeList())){
                            if(StringUtils.isNotBlank(eduEnrollmenBrochureVO.getEnrollArea())){
                                List<String> areaList=Arrays.stream(eduEnrollmenBrochureVO.getEnrollArea().split(",")).map(s -> s).collect(Collectors.toList());
                                if(StringUtils.isNotBlank(eduSchool.getAreaCode())&&!areaList.contains(eduSchool.getAreaCode())){
                                    areaList.add(eduSchool.getAreaCode());
                                }
                                boolean areaFlag=true;
                                for(String area:areaList){
                                    if (eduHouse.getAreaCodeList().contains(area)){
                                        areaFlag=false;
                                        break;
                                    }
                                }
                                if(areaFlag){
                                    throw new AppException("您的房产不在招生范围内，不能报名，如有疑问，请联系学校");
                                }
                            }else{
                                if (!eduHouse.getAreaCodeList().contains(eduSchool.getAreaCode())){
                                    throw new AppException("您的房产不在招生范围内，不能报名，如有疑问，请联系学校");
                                }
                            }
                        }
                        if(eduHouse.getRegisterDate()!=null){
                            if(!BoolEnum.TRUE.getType().equalsIgnoreCase(eduEnrollmenBrochureVO.getHouseEndTimeNo())){
                                //限制房产使用时间
                                Long qysj = Long.parseLong(DateUtil.format(eduHouse.getRegisterDate(), "yyyyMMdd"));
                                if ("0".equalsIgnoreCase(vo.getServiceFlag())) {
                                    //正学区
                                    if (eduEnrollmenBrochureVO.getHouseEndTime() != null) {
                                        Long endTime = Long.parseLong(DateUtil.format(eduEnrollmenBrochureVO.getHouseEndTime(), "yyyyMMdd"));
                                        if (qysj > endTime) {
                                            throw new AppException("您的房产登记时间为：" + qysj + ";大于学校政策中房产截止时间，不能使用房产作为报名条件");
                                        }
                                    }
                                } else {
                                    //服务区
                                    if (eduEnrollmenBrochureVO.getHouseEndTimeFw() != null) {
                                        Long endTime = Long.parseLong(DateUtil.format(eduEnrollmenBrochureVO.getHouseEndTimeFw(), "yyyyMMdd"));
                                        if (qysj > endTime) {
                                            throw new AppException("您的房产登记时间为：" + qysj + ";大于学校招生政策中房产截止时间，不能使用房产作为报名条件");
                                        }
                                    }
                                }
                            }
                        }
                        vo.setRealProperty(eduHouse.getRealProperty());
                        vo.setRealPropertyNum(eduHouse.getRealPropertyNum());
                        vo.setRegisterDate(eduHouse.getRegisterDate());
                        vo.setQlrName(eduHouse.getQlrName());
                        vo.setHouseAdreess(eduHouse.getAddress());
                        //判断是否只能房产所有者才能报名
                        CommonVO commonVO = new CommonVO();
                        commonVO.setParamKey("only_my_house_enroll");
                        String onlyflag = commonIntegration.getValueByKey(commonVO);
                        boolean canEnroll = false;
                        if ("0".equalsIgnoreCase(onlyflag) || "false".equalsIgnoreCase(onlyflag)) {
                            canEnroll = true;
                        } else {
                            if(BoolEnum.TRUE.getType().equalsIgnoreCase(eduStudentEnrollPre.getAgentEnrollFlag())){
                                //代理报名
                                canEnroll = true;
                            }else {
                                List<EduHouseDetailVO> detailVOList = eduHouse.getDetailList();
                                SessionInfo sessionInfo = SessionUtil.getSessionInfo();
                                if (sessionInfo == null) {
                                    throw new AppException("请先登录后再操作");
                                }
                                for (EduHouseDetailVO detailVO : detailVOList) {
                                    if (StringUtils.isBlank(detailVO.getIdcard())) {
                                        if (SessionUtil.getFullName().equalsIgnoreCase(detailVO.getFullName())) {
                                            canEnroll = true;
                                            break;
                                        }
                                    } else {
                                        if (SessionUtil.getSessionInfo().getIdcard().equalsIgnoreCase(detailVO.getIdcard())) {
                                            canEnroll = true;
                                            break;
                                        }
                                        if (vo.getIdcard().equalsIgnoreCase(detailVO.getIdcard())) {
                                            canEnroll = true;
                                            break;
                                        }
                                    }

                                }
                            }

                        }
                        if (!canEnroll) {
                            throw new AppException("您不是房产所有者，不能报名，请使用房产证上的权利人账号登录系统进行报名。");
                        }
                        List<String> xqHouseIdList=new ArrayList<>();
                        if(!CollectionUtils.isEmpty(eduHouse.getGyHouseIdList())&&eduHouse.getGyHouseIdList().size()>1){
                            xqHouseIdList.addAll(eduHouse.getGyHouseIdList());

                        }else{
                            xqHouseIdList.add(vo.getHouseId());

                        }
                        //校验房产对应学区
                        if(!CollectionUtils.isEmpty(eduStudentEnrollPre.getHouseSchoolVOList())){
                            boolean fcxq=false;
                            String fcfwqSchool="";//房产服务区学校
                            String fczxqSchool="";//房产正学区学校
                            boolean fwq=false;//报名学校是否匹配到服务区
                            boolean zxq=false;//报名学校是否匹配到正学区
                            boolean fcfwq=false;//户籍地址是否存在服务区学校
                            boolean fczxq=false;//户籍地址是否存在正学区学校
                            for(HouseSchoolVO houseSchoolVO:eduStudentEnrollPre.getHouseSchoolVOList()){
                                if(xqHouseIdList.contains(houseSchoolVO.getHouseId())){
                                    if(schoolIdList.contains(houseSchoolVO.getSchoolId())){
                                        fcxq=true;
                                        if ("1".equalsIgnoreCase(houseSchoolVO.getServiceAreaFlag())){
                                            fwq=true;
                                        }else{
                                            zxq=true;
                                        }
                                    }
                                    if ("1".equalsIgnoreCase(houseSchoolVO.getServiceAreaFlag())){
                                        fcfwq=true;
                                        if(StringUtils.isBlank(fcfwqSchool)){
                                            fcfwqSchool=houseSchoolVO.getSchoolName();
                                        }else{
                                            if(fcfwqSchool.indexOf("houseSchoolVO.getSchoolName()")<0){
                                                fcfwqSchool=fcfwqSchool+","+houseSchoolVO.getSchoolName();
                                            }

                                        }
                                    }else{
                                        fczxq=true;
                                        if(StringUtils.isBlank(fcfwqSchool)){
                                            fczxqSchool=houseSchoolVO.getSchoolName();
                                        }else{
                                            if(fczxqSchool.indexOf("houseSchoolVO.getSchoolName()")<0){
                                                fczxqSchool=fczxqSchool+","+houseSchoolVO.getSchoolName();
                                            }

                                        }
                                    }

                                }
                            }
                            if(!fcxq){
                                if(vo.getConfigName().equalsIgnoreCase("A")){
                                    //房户一致判断服务区
                                    if(BoolEnum.TRUE.getType().equalsIgnoreCase(vo.getServiceFlag())) {
                                        if (fcfwq) {
                                            throw new AppException("当前您的房产服务区系统匹配为：" + fcfwqSchool + "，不能以此套房产报名其他学校。如有疑问，请联系当前系统匹配房产服务区学校。");
                                        }else{
                                            EduStudentEnrollVerificationVO verificationVO = new EduStudentEnrollVerificationVO();
                                            verificationVO.setVerificationType(VerificationTypeEnum.fcdz.getType());
                                            verificationVO.setVerificationAddress(eduHouse.getAddress());
                                            verificationVO.setVerificationTypeId(vo.getHouseId());
                                            boolean inFlag = true;
                                            for (EduStudentEnrollVerificationVO enrollVerificationVO : verificationVOList) {
                                                if (enrollVerificationVO.getVerificationType().equalsIgnoreCase(verificationVO.getVerificationType())) {
                                                    inFlag = false;
                                                    break;
                                                }
                                            }
                                            if (inFlag) {
                                                verificationVOList.add(verificationVO);
                                            }
                                        }
                                    }else{
                                        if(fczxq){
                                            throw new AppException("当前您的房产正学区系统匹配为："+fczxqSchool+"，不能以此套房产报名其他学校。如有疑问，请联系当前系统匹配房产正学区学校。");
                                        }else{
                                            EduStudentEnrollVerificationVO verificationVO = new EduStudentEnrollVerificationVO();
                                            verificationVO.setVerificationType(VerificationTypeEnum.fcdz.getType());
                                            verificationVO.setVerificationAddress(eduHouse.getAddress());
                                            verificationVO.setVerificationTypeId(vo.getHouseId());
                                            boolean inFlag = true;
                                            for (EduStudentEnrollVerificationVO enrollVerificationVO : verificationVOList) {
                                                if (enrollVerificationVO.getVerificationType().equalsIgnoreCase(verificationVO.getVerificationType())) {
                                                    inFlag = false;
                                                    break;
                                                }
                                            }
                                            if (inFlag) {
                                                verificationVOList.add(verificationVO);
                                            }
                                        }
                                    }
                                }else{
                                    if(fczxq){
                                        throw new AppException("当前您的房产学区系统匹配为："+fczxqSchool+"，不能以此套房产报名其他学校。如有疑问，请联系当前系统匹配房产学区学校。");
                                    }else{
                                        EduStudentEnrollVerificationVO verificationVO = new EduStudentEnrollVerificationVO();
                                        verificationVO.setVerificationType(VerificationTypeEnum.fcdz.getType());
                                        verificationVO.setVerificationAddress(eduHouse.getAddress());
                                        verificationVO.setVerificationTypeId(vo.getHouseId());
                                        boolean inFlag = true;
                                        for (EduStudentEnrollVerificationVO enrollVerificationVO : verificationVOList) {
                                            if (enrollVerificationVO.getVerificationType().equalsIgnoreCase(verificationVO.getVerificationType())) {
                                                inFlag = false;
                                                break;
                                            }
                                        }
                                        if (inFlag) {
                                            verificationVOList.add(verificationVO);
                                        }
                                    }
                                }
                            }
                            if (fwq&&!zxq){
                                if(vo.getConfigName().equalsIgnoreCase("C")){
                                    throw new AppException("您的房产地址被学校设置为服务区，不能报该学校有房无户。如有疑问，请联系学校。");
                                }
                                if(vo.getConfigName().equalsIgnoreCase("A")&&!BoolEnum.TRUE.getType().equalsIgnoreCase(vo.getServiceFlag())){
                                    throw new AppException("您的房产地址被学校设置为服务区，不能报房户一致（正学区）和房户一致（原住民）。如有疑问，请联系学校。");
                                }
                            }
                            if (!fwq&&zxq){
                                if(vo.getConfigName().equalsIgnoreCase("A")&&BoolEnum.TRUE.getType().equalsIgnoreCase(vo.getServiceFlag())){
                                    throw new AppException("您的房产地址被学校设置为服务区，不能报房户一致（服务区）和房户一致（服务区原住民）。如有疑问，请联系学校。");
                                }
                            }
                        }else{
                            EduStudentEnrollVerificationVO verificationVO = new EduStudentEnrollVerificationVO();
                            verificationVO.setVerificationType(VerificationTypeEnum.fcdz.getType());
                            verificationVO.setVerificationAddress(eduHouse.getAddress());
                            verificationVO.setVerificationTypeId(vo.getHouseId());
                            boolean inFlag = true;
                            for (EduStudentEnrollVerificationVO enrollVerificationVO : verificationVOList) {
                                if (enrollVerificationVO.getVerificationType().equalsIgnoreCase(verificationVO.getVerificationType())) {
                                    inFlag = false;
                                    break;
                                }
                            }
                            if (inFlag) {
                                verificationVOList.add(verificationVO);
                            }
                        }
                    }else{
                        LambdaQueryWrapper<EduStudentEnrollWhite> whiteLambdaQueryWrapper=new LambdaQueryWrapper<>();
                        whiteLambdaQueryWrapper.eq(EduStudentEnrollWhite::getIdcard,vo.getIdcard())
                                .eq(EduStudentEnrollWhite::getYear,vo.getYear())
                                .eq(EduStudentEnrollWhite::getAuthStatus,BoolEnum.TRUE.getType())
                                .eq(EduStudentEnrollWhite::getSchoolId,vo.getSchoolId());
                        if(eduStudentEnrollWhiteService.count(whiteLambdaQueryWrapper)<=0){
                            throw new AppException("请使用系统匹配的房产报名，如有误，请联系学校");
                        }else {
                            EduStudentEnrollVerificationVO verificationVO = new EduStudentEnrollVerificationVO();
                            verificationVO.setVerificationType(VerificationTypeEnum.fc.getType());
                            verificationVO.setVerificationAddress(vo.getHouseAdreess());
                            verificationVO.setVerificationTypeId(vo.getHouseId());
                            boolean inFlag = true;
                            for (EduStudentEnrollVerificationVO enrollVerificationVO : verificationVOList) {
                                if (enrollVerificationVO.getVerificationType().equalsIgnoreCase(verificationVO.getVerificationType())) {
                                    inFlag = false;
                                    break;
                                }
                            }
                            if (inFlag) {
                                verificationVOList.add(verificationVO);
                            }
                        }
                    }

                }

                if (checkHousehold) {
                    if(StringUtils.isBlank(vo.getHouseholdId())&&StringUtils.isBlank(vo.getParam17())){
                        throw new AppException("请选择系统匹配的户籍信息或上传户籍佐证材料");
                    }
                    if(StringUtils.isNotBlank(vo.getHouseholdId())) {
                        //校验户籍是否存在
                        EduHouseholdVO eduHousehold = eduStudentEnrollPre.getHouseHoldVO();
                        if (eduHousehold == null || !BoolEnum.TRUE.getType().equals(eduHousehold.getStatus()) || !AuthStatusEnum.YES.getType().equals(eduHousehold.getAuthStatus())) {
                            throw new AppException("不是有效的户籍");
                        }
                        if (!vo.getHouseholdId().equalsIgnoreCase(eduHousehold.getHouseholdId())){
                            throw new AppException("您的户籍信息已更新，请退出系统重新报名");
                        }
                        vo.setQysj(eduHousehold.getQysj());
                        vo.setHouseholdAddress(eduHousehold.getAddress());
                        if(!CollectionUtils.isEmpty(eduHousehold.getAreaCodeList())){
                            if(StringUtils.isNotBlank(eduEnrollmenBrochureVO.getEnrollArea())){
                                List<String> areaList=Arrays.stream(eduEnrollmenBrochureVO.getEnrollArea().split(",")).map(s -> s).collect(Collectors.toList());
                                if(StringUtils.isNotBlank(eduSchool.getAreaCode())&&!areaList.contains(eduSchool.getAreaCode())){
                                    areaList.add(eduSchool.getAreaCode());
                                }
                                boolean areaFlag=true;
                                for(String area:areaList){
                                    if (eduHousehold.getAreaCodeList().contains(area)){
                                        areaFlag=false;
                                        break;
                                    }
                                }
                                if(areaFlag){
                                    throw new AppException("您的户籍不在招生范围内，不能报名，如有疑问，请联系学校");
                                }
                            }else{
                                if (!eduHousehold.getAreaCodeList().contains(eduSchool.getAreaCode())){
                                    throw new AppException("您的户籍不在招生范围内，不能报名，如有疑问，请联系学校");
                                }
                            }

                        }
                        //校验户籍对应学区
                        if(!CollectionUtils.isEmpty(eduStudentEnrollPre.getHouseholdSchoolVOList())){
                            boolean hjxq=false;
                            String hjfwqSchool="";//户籍服务区学校
                            String hjzxqSchool="";//户籍正学区学校
                            boolean fwq=false;//报名学校是否匹配到服务区
                            boolean zxq=false;//报名学校是否匹配到正学区
                            boolean hjfwq=false;//户籍地址是否存在服务区学校
                            boolean hjzxq=false;//户籍地址是否存在正学区学校
                            for(HouseholdSchoolVO householdSchoolVO:eduStudentEnrollPre.getHouseholdSchoolVOList()){
                                if(householdSchoolVO.getHouseholdId().equalsIgnoreCase(eduHousehold.getHouseholdId())){
                                    if(schoolIdList.contains(householdSchoolVO.getSchoolId())){
                                        hjxq=true;
                                        if ("1".equalsIgnoreCase(householdSchoolVO.getServiceAreaFlag())){
                                            fwq=true;
                                        }else{
                                            zxq=true;
                                        }
                                    }
                                    if ("1".equalsIgnoreCase(householdSchoolVO.getServiceAreaFlag())){
                                        hjfwq=true;
                                        if(StringUtils.isBlank(hjfwqSchool)){
                                            hjfwqSchool=householdSchoolVO.getSchoolName();
                                        }else{
                                            hjfwqSchool=hjfwqSchool+","+householdSchoolVO.getSchoolName();
                                        }
                                    }else{
                                        hjzxq=true;
                                        if(StringUtils.isBlank(hjzxqSchool)){
                                            hjzxqSchool=householdSchoolVO.getSchoolName();
                                        }else{
                                            hjzxqSchool=hjzxqSchool+","+householdSchoolVO.getSchoolName();
                                        }
                                    }

                                }
                            }
                            if(!hjxq){
                                if(BoolEnum.TRUE.getType().equalsIgnoreCase(vo.getServiceFlag())) {
                                    if (hjfwq) {
                                        throw new AppException("当前您的户籍服务区系统匹配为：" + hjfwqSchool + "，不能以户籍报名其他学校。如有疑问，请联系当前系统匹配户籍服务区学校。");
                                    }else{
                                        EduStudentEnrollVerificationVO verificationVO = new EduStudentEnrollVerificationVO();
                                        verificationVO.setVerificationType(VerificationTypeEnum.hjdz.getType());
                                        verificationVO.setVerificationAddress(eduHousehold.getAddress());
                                        verificationVO.setVerificationTypeId(vo.getHouseholdId());
                                        boolean inFlag = true;
                                        for (EduStudentEnrollVerificationVO enrollVerificationVO : verificationVOList) {
                                            if (enrollVerificationVO.getVerificationType().equalsIgnoreCase(verificationVO.getVerificationType())) {
                                                inFlag = false;
                                                break;
                                            }
                                        }
                                        if (inFlag) {
                                            verificationVOList.add(verificationVO);
                                        }
                                    }
                                }else{
                                    if(hjzxq){
                                        throw new AppException("当前您的户籍正学区系统匹配为："+hjzxqSchool+"，不能以户籍报名其他学校。如有疑问，请联系当前系统匹配户籍正学区学校。");
                                    }else{
                                        EduStudentEnrollVerificationVO verificationVO = new EduStudentEnrollVerificationVO();
                                        verificationVO.setVerificationType(VerificationTypeEnum.hjdz.getType());
                                        verificationVO.setVerificationAddress(eduHousehold.getAddress());
                                        verificationVO.setVerificationTypeId(vo.getHouseholdId());
                                        boolean inFlag = true;
                                        for (EduStudentEnrollVerificationVO enrollVerificationVO : verificationVOList) {
                                            if (enrollVerificationVO.getVerificationType().equalsIgnoreCase(verificationVO.getVerificationType())) {
                                                inFlag = false;
                                                break;
                                            }
                                        }
                                        if (inFlag) {
                                            verificationVOList.add(verificationVO);
                                        }
                                    }
                                }

                            }
                            if (fwq&&!zxq){
                                if(vo.getConfigName().equalsIgnoreCase("B")){
                                    throw new AppException("您的户籍地址被学校设置为服务区，不能报该学校有户无房。如有疑问，请联系学校。");
                                }
                                if(vo.getConfigName().equalsIgnoreCase("A")&&!BoolEnum.TRUE.getType().equalsIgnoreCase(vo.getServiceFlag())){
                                    throw new AppException("您的户籍地址被学校设置为服务区，不能报房户一致（正学区）和房户一致（原住民）。如有疑问，请联系学校。");
                                }
                                if(vo.getConfigName().equalsIgnoreCase("特殊户口")){
                                    throw new AppException("您的户籍地址被学校设置为服务区，不能报该学校集体户、挂靠户等。如有疑问，请联系学校。");
                                }
                            }
                            if (!fwq&&zxq){
                                if(vo.getConfigName().equalsIgnoreCase("A")&&BoolEnum.TRUE.getType().equalsIgnoreCase(vo.getServiceFlag())){
                                    throw new AppException("您的户籍地址被学校设置为服务区，不能报房户一致（服务区）和房户一致（服务区原住民）。如有疑问，请联系学校。");
                                }
                            }
                        }else{
                            EduStudentEnrollVerificationVO verificationVO = new EduStudentEnrollVerificationVO();
                            verificationVO.setVerificationType(VerificationTypeEnum.hjdz.getType());
                            verificationVO.setVerificationAddress(eduHousehold.getAddress());
                            verificationVO.setVerificationTypeId(vo.getHouseholdId());
                            boolean inFlag = true;
                            for (EduStudentEnrollVerificationVO enrollVerificationVO : verificationVOList) {
                                if (enrollVerificationVO.getVerificationType().equalsIgnoreCase(verificationVO.getVerificationType())) {
                                    inFlag = false;
                                    break;
                                }
                            }
                            if (inFlag) {
                                verificationVOList.add(verificationVO);
                            }
                        }

                    }else{
                        LambdaQueryWrapper<EduStudentEnrollWhite> whiteLambdaQueryWrapper=new LambdaQueryWrapper<>();
                        whiteLambdaQueryWrapper.eq(EduStudentEnrollWhite::getIdcard,vo.getIdcard())
                                .eq(EduStudentEnrollWhite::getYear,vo.getYear())
                                .eq(EduStudentEnrollWhite::getAuthStatus,BoolEnum.TRUE.getType())
                                .eq(EduStudentEnrollWhite::getSchoolId,vo.getSchoolId());
                        if(eduStudentEnrollWhiteService.count(whiteLambdaQueryWrapper)<=0){
                            throw new AppException("请使用系统匹配的户籍报名，如有误，请联系学校");
                        }else{
                            EduStudentEnrollVerificationVO verificationVO = new EduStudentEnrollVerificationVO();
                            verificationVO.setVerificationType(VerificationTypeEnum.hj.getType());
                            verificationVO.setVerificationAddress(vo.getHouseholdAddress());
                            verificationVO.setVerificationTypeId(vo.getHouseholdId());
                            boolean inFlag = true;
                            for (EduStudentEnrollVerificationVO enrollVerificationVO : verificationVOList) {
                                if (enrollVerificationVO.getVerificationType().equalsIgnoreCase(verificationVO.getVerificationType())) {
                                    inFlag = false;
                                    break;
                                }
                            }
                            if (inFlag) {
                                verificationVOList.add(verificationVO);
                            }
                        }
                    }
                    if(StringUtils.isNotBlank(vo.getQysj())){
                        if(!BoolEnum.TRUE.getType().equalsIgnoreCase(eduEnrollmenBrochureVO.getHouseholdEndTimeNo())){
                            Long qysj =null;
                            try {
                                qysj = Long.parseLong(DateUtil.format(DateUtil.parse(vo.getQysj()), "yyyyMMdd"));
                            }catch (Exception e){
                                e.printStackTrace();
                            }
                            if(qysj!=null) {
                                //限制户籍迁入时间
                                if ("0".equalsIgnoreCase(vo.getServiceFlag())) {
                                    //正学区
                                    if (eduEnrollmenBrochureVO.getHouseholdEndTime() != null) {
                                        Long endTime = Long.parseLong(DateUtil.format(eduEnrollmenBrochureVO.getHouseholdEndTime(), "yyyyMMdd"));
                                        if (qysj > endTime) {
                                            throw new AppException("您的户籍迁入时间为：" + vo.getQysj() + ";大于学校招生政策中户籍截止时间，不能使用户籍作为报名条件");
                                        }
                                    }
                                } else {
                                    //服务区
                                    if (eduEnrollmenBrochureVO.getHouseholdEndTimeFw() != null) {
                                        Long endTime = Long.parseLong(DateUtil.format(eduEnrollmenBrochureVO.getHouseholdEndTimeFw(), "yyyyMMdd"));
                                        if (qysj > endTime) {
                                            throw new AppException("您的户籍迁入时间为：" + vo.getQysj() + ";大于学校招生政策中户籍截止时间，不能使用户籍作为报名条件");
                                        }
                                    }
                                }
                            }

                        }
                    }

                }
                List<EduStudentEnrollBeforeVO> boforeList=eduStudentEnrollPre.getEnrollBeforeList();

                if(!CollectionUtils.isEmpty(verificationVOList)){
                    for(EduStudentEnrollVerificationVO verificationVO:verificationVOList){
                        if(verificationVO.getVerificationType().equalsIgnoreCase("6")||verificationVO.getVerificationType().equalsIgnoreCase("8")){
                            if(StringUtils.isBlank(vo.getParam17())){
                                throw new AppException("请上传户口本照片信息");
                            }
                        }
                        if(verificationVO.getVerificationType().equalsIgnoreCase("5")||verificationVO.getVerificationType().equalsIgnoreCase("7")){
                            if(StringUtils.isBlank(vo.getParam16())){
                                throw new AppException("请上传房产佐证材料信息");
                            }
                        }
                        if(verificationVO.getVerificationType().equalsIgnoreCase("1")||verificationVO.getVerificationType().equalsIgnoreCase("11")){
                            if(StringUtils.isBlank(vo.getParam16())){
                                throw new AppException("请上传原住民佐证材料信息");
                            }
                        }
                    }
                }

                if (abcFlag&&!vo.getVerificationFlag()) {
                    EduStudentEnrollBeforeVO before = null;
                    if (vo.getEnrollBeforeId() == null) {
                        throw new AppException("一键报名id不能为空！");
                    }
                    if(!CollectionUtils.isEmpty(boforeList)){
                        for(EduStudentEnrollBeforeVO beforeVO:boforeList){
                            if(beforeVO.getEnrollBeforeId().equals(vo.getEnrollBeforeId())){
                                before=beforeVO;
                            }
                        }
                    }

                    if (before == null) {
                        throw new AppException("系统校验到报名条件存在不符合情况，请退出到系统，重新报名");
                    } else {
                        if (checkHouse) {
                            if (!vo.getHouseId().equals(before.getHouseId())) {
                                throw new AppException("系统校验到房产不符合情况，请退出系统，重新报名");
                            }
                        }
                        if (checkHousehold) {
                            if (!vo.getHouseholdId().equals(before.getHouseholdId())) {
                                throw new AppException("系统校验到户籍不符合情况，请退出系统，重新报名");
                            }

                        }

                    }

                }

                vo.setAppointFlag(BoolEnum.FALSE.getType());
                vo.setAppointStudentId(null);


            }

            boolean xjFlag = false;
            boolean hjFlag = false;
            boolean fcFlag = false;
            boolean wqFlag = false;
            boolean sbFlag = false;
            boolean qyFlag = false;
            boolean jjzFlag = false;
            if (!abcFlag && StringUtils.isNotBlank(vo.getFormId())) {
                //其他类型字段校验必填
                List<EduFormEnrollParamsVO> paramsList = new ArrayList<>();
                if (BoolEnum.TRUE.getType().equals(vo.getSpecialFlag())) {
                    //特殊通道人员，目前没有自定义表单
                } else {
                    Map<String,List<EduFormEnrollParamsVO>>  paramsMap=eduSchool.getFormParams();
                    paramsList = paramsMap.get(vo.getFormId());
                }
                if (!CollectionUtils.isEmpty(configList)) {
                    BeanWrapper beanWrapper = new BeanWrapperImpl(vo);
                    if(!CollectionUtils.isEmpty(paramsList)){
                        for (EduFormEnrollParamsVO config : paramsList) {
                            if (BoolEnum.TRUE.getType().equals(config.getRequiredFlag())) {
                                String param = config.getParam();
                                if (StringUtils.equals(config.getPropertyType(), "1") ||
                                        StringUtils.equals(config.getPropertyType(), "11") ||
                                        StringUtils.equals(config.getPropertyType(), "2") ||
                                        StringUtils.equals(config.getPropertyType(), "3")) {
                                    if (StringUtils.isNotBlank(param) && beanWrapper.isWritableProperty(param)) {
                                        if (ObjectUtils.isEmpty(beanWrapper.getPropertyValue(param))) {
                                            throw new AppException(config.getProperty() + "必填");
                                        }
                                    }
                                } else if (StringUtils.equals(config.getPropertyType(), "4")) {
                                    xjFlag = true;
                                } else if (StringUtils.equals(config.getPropertyType(), "5")) {
                                    hjFlag = true;
                                } else if (StringUtils.equals(config.getPropertyType(), "6")) {
                                    fcFlag = true;
                                } else if (StringUtils.equals(config.getPropertyType(), "7")) {
                                    wqFlag = true;

                                } else if (StringUtils.equals(config.getPropertyType(), "8")) {
                                    sbFlag = true;
                                } else if (StringUtils.equals(config.getPropertyType(), "9")) {
                                    qyFlag = true;
                                } else if (StringUtils.equals(config.getPropertyType(), "10")) {

                                    jjzFlag = true;

                                }
                            }
                        }
                    }

                }
            }
            //判断是否有网签
            if (wqFlag && StringUtils.isBlank(vo.getNetsignId())) {
                throw new AppException("该类别(" + vo.getConfigName() + ")需要有购房合同才能报名");
            }
            List<EduNetsignVO> netsignVOList = eduStudentEnrollPre.getWqList();
            if (!CollectionUtils.isEmpty(netsignVOList)) {
                vo.setNetsignFlag(BoolEnum.FALSE.getType());
                for(EduNetsignVO netsignVO:netsignVOList){
                    if (netsignVO.getNetsignId().equalsIgnoreCase(vo.getNetsignId())) {
                        vo.setNetsignFlag(BoolEnum.TRUE.getType());
                        break;
                    }
                }
                if (wqFlag&&!BoolEnum.TRUE.getType().equalsIgnoreCase(vo.getNetsignFlag())) {
                    throw new AppException("该类别(" + vo.getConfigName() + ")需要有购房合同才能报名");
                }
            } else {
                if (wqFlag) {
                    throw new AppException("该类别(" + vo.getConfigName() + ")需要有购房合同才能报名");
                }
                vo.setNetsignFlag(BoolEnum.FALSE.getType());
            }
            //获取学籍信息
            if (eduStudentEnrollPre.getStudentStatusVO() != null) {
                vo.setStudentStatusId(eduStudentEnrollPre.getStudentStatusVO().getStudentStatusId());
            } else {
                if (xjFlag) {
                    throw new AppException("该类别需要金华学籍信息才能报名" + vo.getConfigName());
                }
            }
            //判断是否有参保
            vo.setCbFlag(BoolEnum.FALSE.getType());
            if (sbFlag ) {
                if(StringUtils.isBlank(vo.getSocialSecurityId())&&StringUtils.isBlank(vo.getParam14())) {
                    throw new AppException("该类别(" + vo.getConfigName() + ")需要在金华正常参保职工养老保险并且连续缴费满6个月以上才能报名,请上传社保证明材料");
                }
                List<EduSocialSecurityVO> sbList=eduStudentEnrollPre.getCbList();
                if (!CollectionUtils.isEmpty(sbList)&&StringUtils.isNotBlank(vo.getSocialSecurityId())) {

                    for (EduSocialSecurityVO socialSecurityVO : sbList) {
                        if (socialSecurityVO.getSocialSecurityId().equalsIgnoreCase(vo.getSocialSecurityId())) {
                            vo.setCbFlag(BoolEnum.TRUE.getType());
                            vo.setCbTotal(socialSecurityVO.getTotal());
                            if(!"330799".equalsIgnoreCase(socialSecurityVO.getAab301())&&!"330701".equalsIgnoreCase(eduSchool.getAreaCode())){
                                //社保市本级的行政区划，多个区都可以报名,市本级学校的，所有社保都可以报名
                                if(StringUtils.isNotBlank(eduEnrollmenBrochureVO.getEnrollArea())){
                                    List<String> areaList=Arrays.stream(eduEnrollmenBrochureVO.getEnrollArea().split(",")).map(s -> s).collect(Collectors.toList());
                                    if(StringUtils.isNotBlank(eduSchool.getAreaCode())&&!areaList.contains(eduSchool.getAreaCode())){
                                        areaList.add(eduSchool.getAreaCode());
                                    }
                                    if(!areaList.contains(socialSecurityVO.getAab301())){
                                        throw new AppException("您的参保区域不是："+eduSchool.getAreaName()+"不能报名该学校");
                                    }
                                }else{
                                    if(!socialSecurityVO.getAab301().equalsIgnoreCase(eduSchool.getAreaCode())){
                                        throw new AppException("您的参保区域不是："+eduSchool.getAreaName()+"不能报名该学校");
                                    }
                                }
                            }
                            break;
                        }
                    }
                    if (!BoolEnum.TRUE.getType().equalsIgnoreCase(vo.getCbFlag())) {
                        throw new AppException("该类别(" + vo.getConfigName() + ")需要在金华市区内正常参保职工养老保险并且连续缴费满6个月以上才能报名");
                    }


                } else {
                    if (StringUtils.isNotBlank(vo.getSocialSecurityId())) {
                        throw new AppException("该类别(" + vo.getConfigName() + ")需要在金华市区内正常参保职工养老保险并且连续缴费满6个月以上才能报名");
                    }
                    if(StringUtils.isNotBlank(vo.getParam14())){
                        vo.setCbFlag(BoolEnum.TRUE.getType());
                        EduStudentEnrollVerificationVO verificationVO=new EduStudentEnrollVerificationVO();
                        verificationVO.setAreaCode(vo.getAreaCode());
                        verificationVO.setVerificationType(VerificationTypeEnum.sb.getType());//社保核验
                        boolean inFlag = true;
                        for (EduStudentEnrollVerificationVO enrollVerificationVO : verificationVOList) {
                            if (enrollVerificationVO.getVerificationType().equalsIgnoreCase(verificationVO.getVerificationType())) {
                                inFlag = false;
                                break;
                            }
                        }
                        if (inFlag) {
                            verificationVOList.add(verificationVO);
                        }
                    }else{
                        vo.setCbFlag(BoolEnum.FALSE.getType());
                        throw new AppException("请上传社保证明照片");
                    }

                }
            }
            //判断是否有居住证
            vo.setLivePlaceFlag(BoolEnum.FALSE.getType());
            if (jjzFlag ) {
                if(StringUtils.isBlank(vo.getLivePlaceId())&&StringUtils.isBlank(vo.getParam13())){
                    throw new AppException("该类别(" + vo.getConfigName() + ")需要金华市区内居住证信息才能报名,请上传居住证证明材料");
                }
                List<EduLivePlaceVO> jzzList=eduStudentEnrollPre.getJzzList();
                if (!CollectionUtils.isEmpty(jzzList)&&StringUtils.isNotBlank(vo.getLivePlaceId())) {

                    for (EduLivePlaceVO livePlaceVO : jzzList) {
                        if (livePlaceVO.getLivePlaceId().equalsIgnoreCase(vo.getLivePlaceId())) {
                            vo.setLivePlaceFlag(BoolEnum.TRUE.getType());
                            if(StringUtils.isNotBlank(eduEnrollmenBrochureVO.getEnrollArea())){
                                List<String> areaList=Arrays.stream(eduEnrollmenBrochureVO.getEnrollArea().split(",")).map(s -> s).collect(Collectors.toList());
                                if(StringUtils.isNotBlank(eduSchool.getAreaCode())&&!areaList.contains(eduSchool.getAreaCode())){
                                    areaList.add(eduSchool.getAreaCode());
                                }
                                if(!areaList.contains(livePlaceVO.getAreaCode())){
                                    throw new AppException("您的居住证区域不是："+eduSchool.getAreaName()+"不能报名该学校");
                                }
                            }else{
                                if(!livePlaceVO.getAreaCode().equalsIgnoreCase(eduSchool.getAreaCode())){
                                    throw new AppException("您的居住证区域不是："+eduSchool.getAreaName()+"不能报名该学校");
                                }
                            }
                            break;
                        }
                    }
                    if (!BoolEnum.TRUE.getType().equalsIgnoreCase(vo.getLivePlaceFlag())) {
                        throw new AppException("该类别(" + vo.getConfigName() + ")需要金华市区内居住证信息才能报名");
                    }
                } else {
                    if (StringUtils.isNotBlank(vo.getLivePlaceId())) {
                        throw new AppException("该类别(" + vo.getConfigName() + ")需要金华市区内居住证信息才能报名");
                    }
                    if(StringUtils.isNotBlank(vo.getParam13())){
                        vo.setLivePlaceFlag(BoolEnum.TRUE.getType());
                        EduStudentEnrollVerificationVO verificationVO=new EduStudentEnrollVerificationVO();
                        verificationVO.setAreaCode(vo.getAreaCode());
                        verificationVO.setVerificationType(VerificationTypeEnum.jzz.getType());//社保核验
                        boolean inFlag = true;
                        for (EduStudentEnrollVerificationVO enrollVerificationVO : verificationVOList) {
                            if (enrollVerificationVO.getVerificationType().equalsIgnoreCase(verificationVO.getVerificationType())) {
                                inFlag = false;
                                break;
                            }
                        }
                        if (inFlag) {
                            verificationVOList.add(verificationVO);
                        }
                    }else{
                        vo.setLivePlaceFlag(BoolEnum.FALSE.getType());
                        throw new AppException("请拍照上传居住证照片");
                    }
                }
            }
            //开办企业
            if (qyFlag && StringUtils.isBlank(vo.getCompanyId())) {
                throw new AppException("该类别(" + vo.getConfigName() + ")需要在金华有开办企业才能报名");
            }
            List<EduCompanyVO> qyList=eduStudentEnrollPre.getQyList();
            if (!CollectionUtils.isEmpty(qyList)) {
                vo.setQyFlag(BoolEnum.FALSE.getType());
                for(EduCompanyVO companyVO:qyList){
                    if (companyVO.getCompanyId().equalsIgnoreCase(vo.getCompanyId())) {
                        vo.setQyFlag(BoolEnum.TRUE.getType());
                        break;
                    }
                }
                if (qyFlag&&!BoolEnum.TRUE.getType().equalsIgnoreCase(vo.getQyFlag())) {
                    throw new AppException("该类别(" + vo.getConfigName() + ")需要在金华有开办企业才能报名");
                }
            } else {
                vo.setQyFlag(BoolEnum.FALSE.getType());
                if (qyFlag) {
                    throw new AppException("该类别(" + vo.getConfigName() + ")需要在金华有开办企业才能报名");
                }
            }
            //户籍
            if (hjFlag) {
                if(StringUtils.isBlank(vo.getHouseholdId())&&StringUtils.isBlank(vo.getParam17())){
                    throw new AppException("请选择系统匹配的户籍信息或上传户籍佐证材料");
                }
                if(StringUtils.isNotBlank(vo.getHouseholdId())) {
                    //校验户籍是否存在
                    EduHouseholdVO eduHousehold = eduStudentEnrollPre.getHouseHoldVO();
                    if (eduHousehold == null || !BoolEnum.TRUE.getType().equals(eduHousehold.getStatus()) || !AuthStatusEnum.YES.getType().equals(eduHousehold.getAuthStatus())) {
                        throw new AppException("不是有效的户籍");
                    }
                    if (!vo.getHouseholdId().equalsIgnoreCase(eduHousehold.getHouseholdId())){
                        throw new AppException("您的户籍信息已更新，请退出系统重新报名");
                    }
                    vo.setQysj(eduHousehold.getQysj());
                    vo.setHouseholdAddress(eduHousehold.getAddress());
                    if(!CollectionUtils.isEmpty(eduHousehold.getAreaCodeList())){
                        if(StringUtils.isNotBlank(eduEnrollmenBrochureVO.getEnrollArea())){
                            List<String> areaList=Arrays.stream(eduEnrollmenBrochureVO.getEnrollArea().split(",")).map(s -> s).collect(Collectors.toList());
                            if(StringUtils.isNotBlank(eduSchool.getAreaCode())&&!areaList.contains(eduSchool.getAreaCode())){
                                areaList.add(eduSchool.getAreaCode());
                            }
                            boolean areaFlag=true;
                            for(String area:areaList){
                                if (eduHousehold.getAreaCodeList().contains(area)){
                                    areaFlag=false;
                                    break;
                                }
                            }
                            if(areaFlag){
                                throw new AppException("您的户籍不在招生范围内，不能报名，如有疑问，请联系学校");
                            }
                        }else{
                            if (!eduHousehold.getAreaCodeList().contains(eduSchool.getAreaCode())){
                                throw new AppException("您的户籍不在招生范围内，不能报名，如有疑问，请联系学校");
                            }
                        }
                    }

                }else{
                    LambdaQueryWrapper<EduStudentEnrollWhite> whiteLambdaQueryWrapper=new LambdaQueryWrapper<>();
                    whiteLambdaQueryWrapper.eq(EduStudentEnrollWhite::getIdcard,vo.getIdcard())
                            .eq(EduStudentEnrollWhite::getYear,vo.getYear())
                            .eq(EduStudentEnrollWhite::getAuthStatus,BoolEnum.TRUE.getType())
                            .eq(EduStudentEnrollWhite::getSchoolId,vo.getSchoolId());
                    if(eduStudentEnrollWhiteService.count(whiteLambdaQueryWrapper)<=0){
                        throw new AppException("请使用系统匹配的户籍报名，如有误，请联系学校");
                    }else{
                        EduStudentEnrollVerificationVO verificationVO = new EduStudentEnrollVerificationVO();
                        verificationVO.setVerificationType(VerificationTypeEnum.hj.getType());
                        verificationVO.setVerificationAddress(vo.getHouseholdAddress());
                        verificationVO.setVerificationTypeId(vo.getHouseholdId());
                        boolean inFlag = true;
                        for (EduStudentEnrollVerificationVO enrollVerificationVO : verificationVOList) {
                            if (enrollVerificationVO.getVerificationType().equalsIgnoreCase(verificationVO.getVerificationType())) {
                                inFlag = false;
                                break;
                            }
                        }
                        if (inFlag) {
                            verificationVOList.add(verificationVO);
                        }
                    }
                }
                if(StringUtils.isNotBlank(vo.getQysj())){
                    if(!BoolEnum.TRUE.getType().equalsIgnoreCase(eduEnrollmenBrochureVO.getHouseholdEndTimeNo())){
                        Long qysj =null;
                        try {
                            qysj = Long.parseLong(DateUtil.format(DateUtil.parse(vo.getQysj()), "yyyyMMdd"));
                        }catch (Exception e){
                            e.printStackTrace();
                        }
                        if(qysj!=null) {
                            //限制户籍迁入时间
                            if ("0".equalsIgnoreCase(vo.getServiceFlag())) {
                                //正学区
                                if (eduEnrollmenBrochureVO.getHouseholdEndTime() != null) {
                                    Long endTime = Long.parseLong(DateUtil.format(eduEnrollmenBrochureVO.getHouseholdEndTime(), "yyyyMMdd"));
                                    if (qysj > endTime) {
                                        throw new AppException("您的户籍迁入时间为：" + vo.getQysj() + ";大于学校招生政策中户籍截止时间，不能使用户籍作为报名条件");
                                    }
                                }
                            } else {
                                //服务区
                                if (eduEnrollmenBrochureVO.getHouseholdEndTimeFw() != null) {
                                    Long endTime = Long.parseLong(DateUtil.format(eduEnrollmenBrochureVO.getHouseholdEndTimeFw(), "yyyyMMdd"));
                                    if (qysj > endTime) {
                                        throw new AppException("您的户籍迁入时间为：" + vo.getQysj() + ";大于学校招生政策中户籍截止时间，不能使用户籍作为报名条件");
                                    }
                                }
                            }
                        }

                    }
                }

            }
            //房产
            if (fcFlag) {
                //校验房产是否存在
                if(StringUtils.isBlank(vo.getHouseId())&&StringUtils.isBlank(vo.getParam16())){
                    throw new AppException("请传入选择报名使用的房产或上传房产佐证材料");
                }
                if(StringUtils.isNotBlank(vo.getHouseId())) {
                    List<EduHouseVO> houseVOList = eduStudentEnrollPre.getHouseList();
                    if (CollectionUtils.isEmpty(houseVOList)) {
                        throw new AppException("未匹配到您名下的房产信息，请使用房产所有者的浙里办账号登录报名。如果匹配信息有误，请联系学校");
                    }
                    EduHouseVO eduHouse = null;
                    for (EduHouseVO eduHouseVO : houseVOList) {
                        if (eduHouseVO.getHouseId().equalsIgnoreCase(vo.getHouseId())) {
                            eduHouse = eduHouseVO;
                            break;
                        }else{
                            if(!CollectionUtils.isEmpty(eduHouseVO.getGyHouseIdList())){
                                if(eduHouseVO.getGyHouseIdList().contains(vo.getHouseId())){
                                    eduHouse=eduHouseVO;
                                    break;
                                }
                            }
                        }
                    }
                    if (eduHouse == null || !BoolEnum.TRUE.getType().equals(eduHouse.getStatus())) {
                        throw new AppException("不是有效的房产");
                    }
                    if(!CollectionUtils.isEmpty(eduHouse.getAreaCodeList())){
                        if(StringUtils.isNotBlank(eduEnrollmenBrochureVO.getEnrollArea())){
                            List<String> areaList=Arrays.stream(eduEnrollmenBrochureVO.getEnrollArea().split(",")).map(s -> s).collect(Collectors.toList());
                            if(StringUtils.isNotBlank(eduSchool.getAreaCode())&&!areaList.contains(eduSchool.getAreaCode())){
                                areaList.add(eduSchool.getAreaCode());
                            }
                            boolean areaFlag=true;
                            for(String area:areaList){
                                if (eduHouse.getAreaCodeList().contains(area)){
                                    areaFlag=false;
                                    break;
                                }
                            }
                            if(areaFlag){
                                throw new AppException("您的房产不在招生范围内，不能报名，如有疑问，请联系学校");
                            }
                        }else{
                            if (!eduHouse.getAreaCodeList().contains(eduSchool.getAreaCode())){
                                throw new AppException("您的房产不在招生范围内，不能报名，如有疑问，请联系学校");
                            }
                        }

                    }
                    if(eduHouse.getRegisterDate()!=null){
                        if(!BoolEnum.TRUE.getType().equalsIgnoreCase(eduEnrollmenBrochureVO.getHouseEndTimeNo())){
                            //限制房产使用时间
                            Long qysj = Long.parseLong(DateUtil.format(eduHouse.getRegisterDate(), "yyyyMMdd"));
                            if (eduEnrollmenBrochureVO.getHouseEndTime() != null) {
                                Long endTime = Long.parseLong(DateUtil.format(eduEnrollmenBrochureVO.getHouseEndTime(), "yyyyMMdd"));
                                if (qysj > endTime) {
                                    throw new AppException("您的房产登记时间为：" + qysj + ";大于学校政策中房产截止时间，不能使用房产作为报名条件");
                                }
                            }

                        }
                    }
                    vo.setRealProperty(eduHouse.getRealProperty());
                    vo.setRealPropertyNum(eduHouse.getRealPropertyNum());
                    vo.setRegisterDate(eduHouse.getRegisterDate());
                    vo.setQlrName(eduHouse.getQlrName());
                    vo.setHouseAdreess(eduHouse.getAddress());
                    //判断是否只能房产所有者才能报名
                    CommonVO commonVO = new CommonVO();
                    commonVO.setParamKey("only_my_house_enroll");
                    String onlyflag = commonIntegration.getValueByKey(commonVO);
                    boolean canEnroll = false;
                    if ("0".equalsIgnoreCase(onlyflag) || "false".equalsIgnoreCase(onlyflag)) {
                        canEnroll = true;
                    } else {
                        if(BoolEnum.TRUE.getType().equalsIgnoreCase(eduStudentEnrollPre.getAgentEnrollFlag())){
                            //代理报名
                            canEnroll = true;
                        }else {
                            List<EduHouseDetailVO> detailVOList = eduHouse.getDetailList();
                            SessionInfo sessionInfo = SessionUtil.getSessionInfo();
                            if (sessionInfo == null) {
                                throw new AppException("请先登录后再操作");
                            }
                            for (EduHouseDetailVO detailVO : detailVOList) {
                                if (StringUtils.isBlank(detailVO.getIdcard())) {
                                    if (SessionUtil.getFullName().equalsIgnoreCase(detailVO.getFullName())) {
                                        canEnroll = true;
                                        break;
                                    }
                                } else {
                                    if (SessionUtil.getSessionInfo().getIdcard().equalsIgnoreCase(detailVO.getIdcard())) {
                                        canEnroll = true;
                                        break;
                                    }
                                    if (vo.getIdcard().equalsIgnoreCase(detailVO.getIdcard())) {
                                        canEnroll = true;
                                        break;
                                    }
                                }

                            }
                        }

                    }
                    if (!canEnroll) {
                        throw new AppException("您不是房产所有者，不能报名，请使用房产证上的权利人账号登录系统进行报名。");
                    }

                }else{
                    LambdaQueryWrapper<EduStudentEnrollWhite> whiteLambdaQueryWrapper=new LambdaQueryWrapper<>();
                    whiteLambdaQueryWrapper.eq(EduStudentEnrollWhite::getIdcard,vo.getIdcard())
                            .eq(EduStudentEnrollWhite::getYear,vo.getYear())
                            .eq(EduStudentEnrollWhite::getAuthStatus,BoolEnum.TRUE.getType())
                            .eq(EduStudentEnrollWhite::getSchoolId,vo.getSchoolId());
                    if(eduStudentEnrollWhiteService.count(whiteLambdaQueryWrapper)<=0){
                        throw new AppException("请使用系统匹配的房产报名，如有误，请联系学校");
                    }else {
                        EduStudentEnrollVerificationVO verificationVO = new EduStudentEnrollVerificationVO();
                        verificationVO.setVerificationType(VerificationTypeEnum.fc.getType());
                        verificationVO.setVerificationAddress(vo.getHouseAdreess());
                        verificationVO.setVerificationTypeId(vo.getHouseId());
                        boolean inFlag = true;
                        for (EduStudentEnrollVerificationVO enrollVerificationVO : verificationVOList) {
                            if (enrollVerificationVO.getVerificationType().equalsIgnoreCase(verificationVO.getVerificationType())) {
                                inFlag = false;
                                break;
                            }
                        }
                        if (inFlag) {
                            verificationVOList.add(verificationVO);
                        }
                    }
                }
            }
            //遇到一方家庭关系比对通过的情况，如果登录方是比对通过一方，则家庭关系设置为比对通过
            if ("2".equalsIgnoreCase(eduStudentEnrollPre.getFamilyFlag())||"3".equalsIgnoreCase(eduStudentEnrollPre.getFamilyFlag())){
                String loginIdcard=SessionUtil.getSessionInfo()!=null?SessionUtil.getSessionInfo().getIdcard():"";
                if(StringUtils.isNotBlank(loginIdcard)){
                    if ("2".equalsIgnoreCase(eduStudentEnrollPre.getFamilyFlag())){
                        if(StringUtils.isNotBlank(eduStudentEnrollPre.getFatherIdcard())&&eduStudentEnrollPre.getFatherIdcard().equalsIgnoreCase(loginIdcard)){
                            eduStudentEnrollPre.setFamilyFlag("1");
                        }
                    }
                    if ("3".equalsIgnoreCase(eduStudentEnrollPre.getFamilyFlag())){
                        if(StringUtils.isNotBlank(eduStudentEnrollPre.getMotherIdcard())&&eduStudentEnrollPre.getMotherIdcard().equalsIgnoreCase(loginIdcard)){
                            eduStudentEnrollPre.setFamilyFlag("1");
                        }
                    }
                }
            }
            if(!BoolEnum.TRUE.getType().equalsIgnoreCase(eduStudentEnrollPre.getFamilyFlag())){
                EduStudentEnrollVerificationVO verificationVO=new EduStudentEnrollVerificationVO();
                verificationVO.setAreaCode(vo.getAreaCode());
                verificationVO.setVerificationType(VerificationTypeEnum.qzgx.getType());//亲子关系核验
                boolean inFlag = true;
                for (EduStudentEnrollVerificationVO enrollVerificationVO : verificationVOList) {
                    if (enrollVerificationVO.getVerificationType().equalsIgnoreCase(verificationVO.getVerificationType())) {
                        inFlag = false;
                        break;
                    }
                }
                if (inFlag) {
                    verificationVOList.add(verificationVO);
                }
                if("2".equalsIgnoreCase(eduStudentEnrollPre.getFamilyFlag())||"3".equalsIgnoreCase(eduStudentEnrollPre.getFamilyFlag())){

                }else{
                    if (StringUtils.isBlank(vo.getParam17())){
                        throw new AppException("请上传户口本信息");
                    }


                }
            }
            vo.setVerificationVOList(verificationVOList);
            if(!CollectionUtils.isEmpty(verificationVOList)){
                vo.setIcertificatioFlag(BoolEnum.TRUE.getType());
            }
            if(!BoolEnum.TRUE.getType().equals(vo.getPrivateAppointFlag())&&vo.getConfigName().equalsIgnoreCase("直升")){
                vo.setPrivateAppointFlag(BoolEnum.TRUE.getType());


            }
            if(BoolEnum.TRUE.getType().equals(vo.getPrivateAppointFlag())){
                //直升班
                if(eduStudentEnrollPre.getZsbVO()==null){
                    throw new AppException("您的孩子不在学校直升班名单范围内，如有疑问请联系学校");
                }else{
                    if(!eduStudentEnrollPre.getZsbVO().getSchoolId().equalsIgnoreCase(vo.getSchoolId())){
                        throw new AppException("您的孩子不在学校直升班名单范围内，如有疑问请联系学校");
                    }
                }
                vo.setPrivateAppointStudentId(eduStudentEnrollPre.getZsbVO().getPrivateAppointStudentId());
            }else{
                vo.setPrivateAppointStudentId(null);
                vo.setPrivateAppointFlag(null);
            }
        }
        if(vo.getEnrollNum()==null){
            vo.setEnrollNum(1);
            if (BoolEnum.TRUE.getType().equalsIgnoreCase(vo.getBbFlag())){
                vo.setEnrollNum(2);
            }
            if (BoolEnum.TRUE.getType().equalsIgnoreCase(vo.getSpareRegisterFlag())){
                vo.setEnrollNum(3);
            }
        }
    }
    private void checkFull(SaveStudentEnrollVO vo,EduSchoolConfigVO schoolConfig){
        if(schoolConfig==null){
            throw new AppException(vo.getYear()+"年度报名学校未配置招生计划，如有疑问，请拨打学校电话了解详细情况");
        }
        //计划人数
        Integer enrolment = 0;
        enrolment = schoolConfig.getEnrolment() == null ? 0 : schoolConfig.getEnrolment();
        //已录取+报名人数
        QueryWrapper<EduStudentEnrollImitate> lqQuery = new QueryWrapper<>();
        List<String> enrollStatusList=new ArrayList<>();
        enrollStatusList.add(EnrollStatusFormalEnum.hy.getType());
        enrollStatusList.add(EnrollStatusFormalEnum.fs.getType());
        enrollStatusList.add(EnrollStatusFormalEnum.dsh.getType());
        enrollStatusList.add(EnrollStatusFormalEnum.dlq.getType());
        enrollStatusList.add(EnrollStatusFormalEnum.lq.getType());
        lqQuery.lambda().in(EduStudentEnrollImitate::getEnrollStatus, enrollStatusList)
                .eq(EduStudentEnrollImitate::getYear, vo.getYear())
                .eq(EduStudentEnrollImitate::getSchoolId, vo.getSchoolId());
        if ("1".equals(vo.getSchoolNature()) || "2".equals(vo.getSchoolNature())) {
            //民办
            lqQuery.lambda().eq(EduStudentEnrollImitate::getConfigTypeName, vo.getConfigTypeName());
        }
        Long lqCount = eduStudentEnrollService.count(lqQuery);
        if (lqCount >= enrolment) {
            throw new AppException("报名已满");
        }
    }
}
